1
$\begingroup$

I have read in 600 thresholded gray scale images (located here - 14MB, png, 8bit, 300*200 pixel) into Image3D with:

ChoiceDialog[{FileNameSetter[Dynamic[imageDir], "Directory"], Dynamic[imageDir]}];
SetDirectory[imageDir];

fNames = FileNames["*.png"];

numFiles = Length@fNames;

readImage[index_] := 
  Binarize[First@Image`ImportExportDump`ImageReadPNG[fNames[[index]]], 
    FindThreshold@First@Image`ImportExportDump`ImageReadPNG[fNames[[index]]]];

imagesArray3dArray = Image3D[Table[readImage[i], {i, numFiles}]];

The physical dimension of each pixel in x direction is 14 mum, in y direction 12 mum and the "thickness" of an image is 2 mum (corresponding to z direction).

Now I want to plot the 3d volume with the proper axes ranges.

I tried:

imagesSlices = Image3DSlices[imagesArray3dArray];

xPixelSize = 14;
yPixelSize = 12;
zPixelSize = 2;

dim = ImageDimensions[imagesArray3dArray];

Image3D[imagesSlices, BoxRatios -> {dim[[1]]*xPixelSize, dim[[2]]*yPixelSize, 
dim[[3]]*zPixelSize}, Boxed -> True, Axes -> True, AxesLabel -> {"x", "y", "z"}]

The result is:

enter image description here

As you see the axes ranges of x and y are plotted in pixel values and z corresponds to the image number.

How can I show the axes ranges in physical dimensions considering the correct aspect ratio?

$\endgroup$
  • 1
    $\begingroup$ Just as a note, I think Mathematica at the moment does not support custom voxel sizes, Image3D just assumes that the loaded image has voxel size 1x1x1. So if you want to apply morphological operations correctly, you would have to modify the image stack, as I had to painfully learn here: mathematica.stackexchange.com/questions/155281/… But since you are just asking about visualisation purposes, this may not be important. $\endgroup$ – Alexander Erlich Oct 9 '17 at 16:04
  • $\begingroup$ Related. $\endgroup$ – corey979 Jan 7 '18 at 22:10
0
$\begingroup$

I have borrowed the lower solution form here:

Needs["CustomTicks`"]

{xdim, ydim, zdim} = ImageDimensions[imagesArray3dArray]

{xmax, ymax, zmax} = {xdim*xPixelSize, ydim*yPixelSize, zdim*zPixelSize}/10

Show[Image3D[imagesSlices], 
 BoxRatios -> {xdim*xPixelSize, ydim*yPixelSize, zdim*zPixelSize}, 
 Boxed -> True, Axes -> True, AxesLabel -> {"x (mm)", "y (mm)", "z (mm)"}, 
 Ticks -> {LinTicks[0, xmax, TickPostTransformation -> (# xdim/xmax &)], 
   LinTicks[0, ymax, TickPostTransformation -> (# ydim/ymax &)], 
   LinTicks[0, zmax, TickPostTransformation -> (# zdim/zmax &)]}]

enter image description here

Since this solution is from 2013 (but works well), I would like to ask if Mathematica 11.2 provides other possibilities, which were not present some years ago.

$\endgroup$
  • 1
    $\begingroup$ I like to use the DataRange->{...} option for converting ticks, I think that's fairly new. It requires slightly less work since you don't have to explicitly list the ticks, but the result is the same. $\endgroup$ – N.J.Evans Oct 9 '17 at 19:14
  • 2
    $\begingroup$ @N.J.Evans - that's the problem though, that Image3D has no DataRange option, probably because Image doesn't have that option either. $\endgroup$ – Jason B. Oct 9 '17 at 19:16
  • $\begingroup$ @Jason: Thank you for your solution which I found in the upper link. Do you think such kind of a 3d plot can be obtained differently? $\endgroup$ – mrz Oct 9 '17 at 19:19
  • 1
    $\begingroup$ @mrz - Is there any way to use ListDensityPlot3D for your application? Being a plotting function it has access to more of the options you want. But I have no idea how to make it color the data in the same way that Image3D does. $\endgroup$ – Jason B. Oct 9 '17 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.