Skip to main content

image - Rendering a 3D volume with Image3D


I have 2D JPEG images, of 1024 x 1024 pixels, corresponding to a 500 x 500 square micron section. These images are taken from slices of tissue, each slice seperated by 10 microns. I've been trying to use Image3D to render these images, and have imported all the images, labelling them h1 to h21. I'm having some difficulty telling Mathematica what separation they should have, but I have tried using BoxRatio to get around this. So far I have;


 H = Image3D[{h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, 
h14, h15, h16, h17, h18, h19, h20, h21}, BoxRatios -> {1, 1, 0.21}];

Show[H, BoxRatios -> {1, 1, 0.42}]

Which displays out an image like this;


enter image description here



This shows the surface information, but seems to hide any of the internal information. I tried using Opacity[0.5] initially, but this did not work. Then I tried


 ColorFunction->Opacity[0.5] 

and this didn't work any better. Is there a way to make the slices opaque, and more importantly, is there a better method to read in and render the images? Thanks!



Answer



Image3D is great, but if you want to have fine-tuned control over the opacity then you need to go to DensityPlot3D, or, in this case, ListDensityPlot3D. These are new functions in version 10.2.


In the absence of OP's data, we'll have to invent some data. OP has a set of slices that together make up a 3D object. We can mimic this using Image3DSlices, and we'll use one of the examples from that page.


Get["http://pastebin.com/raw/x1BY2cpu"]
i


enter image description here


The slices are


 Image3DSlices[i]

enter image description here


Now we could just feed these slices back to Image3D to get the original image, which is essentially what OP has done. But what I'd like to do is instead turn this into numeric data,


list = ImageData /@ Image3DSlices[i];

Now we need to deal with the opacity of the 3D density plot. DensityPlot3D and ListDensityPlot3D can take both an OpacityFunction and a ColorFunction, each of which has Scaling option. By default, the plot will feed scaled values to the opacity function, values between 0 and 1, and map these to opacity values that are also between zero and one. I have toyed around and I like using an exponential opacity function with an adjustable parameter. Here is what it looks like with a few different values of this parameter


Plot[Evaluate[(Exp[# f] - 1)/(E^# - 1) & /@ {1, 4, 8, 12}], {f, 0, 1}]


enter image description here


So the blue curve will scale the opacity nearly linearly with the function value (the brightness of the image), while the red curve will make only the largest values opaque.


Now let's use this opacity function with a density plot, and here I've specified the viewpoint since my machine is slow when manually rotating a 3D density plot,


ListDensityPlot3D[list, 
OpacityFunction -> Function[f, (Exp[# f] - 1)/(E^# - 1)],
ColorFunction -> Hue,
ViewPoint -> {-1.18, -0.05, 3.18},
ViewVertical -> {-0.96, 0, 0.27},
ImageSize -> 300] & /@ {1, 4, 8, 12}


enter image description here


By adjusting the opacity you can hide or highlight the internal structure. It's far too intensive, at least on my machine, to be able to pair with Manipulate and see the opacity changes in real time, but this may change in future implementations.


Another point, is that since this is a ListPlot variant instead of an Image3D, you can specify the DataRange or change the Ticks in any way you want.


Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.