-1
$\begingroup$

I would like to construct a 3D image from 900 2D images in DICOM format in a folder. I am fairly new to mathematica and would greatly appreciate your help. I am currently using Mathematica 11. I used the following loop code to import all the images. Now the images are stored under the variable names imagevar[1], imagevar[2], imagevar[3] so on till imagevar[968]. Now I am trying to use Image3D to generate the 3d image from these variables and it is working when I incorporate the variables into into Image3D function individually (This is the code: Image3D[{imagevar[1],imagevar[2],....,imagevar[968]}] ) but this would take ridiculously long. . I tried using various loop methods to do it faster but it does not seem to work. Please explain how to generate the 3d image in a quick way. Thank you.

$\endgroup$

closed as off-topic by m_goldberg, MarcoB, happy fish, yohbs, J. M. is away May 20 '17 at 6:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – m_goldberg, MarcoB, happy fish, yohbs, J. M. is away
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ What FileNames["somePath/*.dcm"] returns for you? Is it a list of filenames? Also please upload somewhere a subset of your images in order to allow us to experiment with them. You can upload for example to sendspace.com or to filefactory.com. $\endgroup$ – Alexey Popkov May 17 '17 at 3:54
  • $\begingroup$ Hello, I have edited the question and have figured out how to import these files. Please help. Thank you $\endgroup$ – Shriram Bobbili May 17 '17 at 18:09
  • 1
    $\begingroup$ Without you supplying (a subset of) the images, it'd be hard to help you. $\endgroup$ – J. M. is away May 17 '17 at 18:14
  • $\begingroup$ It looks like you want Image3D[Array[imagevar, 968]] $\endgroup$ – Simon Woods May 17 '17 at 18:37
3
$\begingroup$

Simon Woods has provided an answer that is correct as far as I can tell from the question:

Image3D@Array[imagevar, 968] (* or Image3D@Table[imagevar[k], {k,968}] etc.*)

This answer can't improve on that per se, but I wanted to point out a few things about using DICOM files in Mathematica:

  1. Mathematica's Image3D is made for images and not for MRImages; when you load your data into an Image3D, it will normalize all of the values to be in the range of 0-1. For most MRI this doesn't matter, but if you are hoping to be rely on the voxel contrast to be a particular value (e.g., some programs rely on white matter voxels to be approximately a certain value), you'll lose that ability.
  2. If you are dealing with brain data, then one way around this problem is to convert the file to a Nifti file (e.g., using FreeSurfer or some other free sofrware) then load it using the Neurotica package, which is freely available on github. If you've imported Neurotica, Import["someFile.nii", "NifTI"] will return an MRImage3D object (which is defined by the library); these objects imitate Image3D objects but store the original values instead of rescaled values. (They also have some reorientation functions defined on them if you are dealing with oriented brain data.) Note: Neurotica is a research toolkit I maintain; it's mostly for cortical surface analysis so the volumetric routines aren't well tested. I would only recommend this if you are dealing with brain data and want the original values preserved.
$\endgroup$
  • $\begingroup$ Thank you for the help, it seems to be working. Also if I wanted to make the 3d image using only a section of the Images (say images 200 to 300), will Image3D[Array[imagevar, 200,300]] work? $\endgroup$ – Shriram Bobbili May 19 '17 at 18:48
  • $\begingroup$ You'll need to do something like Image3D[Array[imagevar, 100, {200,300}]] or `Image3D@Table[imagevar[k], {k, 200, 300}]; you can refer to this help page: reference.wolfram.com/language/ref/Array.html $\endgroup$ – nben May 20 '17 at 2:13

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