Asked by maha mohy
on 8 Mar 2012

Hello everybody,my graduation project is about 3D mri visualization ,I want to convert 2D images into 3D ...could anyone help me plz

Answer by Image Analyst
on 8 Mar 2012

Accepted answer

try cat(3,...)

image3D = cat(3, slice1, slice2, slice3, slice4, slice5);

You could put it into a loop

for slice = 1 : totalNumberOfSlices thisSlice = GetSlice(); % Whatever you have to do to get one 2D image. if slice == 1 image3D = thisSlice; else image3D = cat(3, image3D, thisSlice); end end

Show 4 older comments

Image Analyst
on 31 May 2016

MATLAB does not have powerful 3D visualization capabilities. For that you can use something like Amira. MATLAB has only basic slice views and isosurfaces.

Charissa Enget
on 1 Jun 2016

oh that makes sense, what if the number of slices is unknown?

Image Analyst
on 1 Jun 2016

When is it unknown? Certainly when it's a 3-D variable in MATLAB the number of slices is known:

[rows, columns, numSlices] = size(array3D);

Log in to comment.

Answer by Walter Roberson
on 8 Mar 2012

The problem is not constructing the 3D array: the problem is displaying it. MATLAB does not have good voxel visualization routines. You could try http://www.mathworks.com/matlabcentral/fileexchange/3280-voxel

Image Analyst
on 8 Mar 2012

How did you decide that? Displaying is converting a 3D volumetric image into a 2D projection image - the opposite of what he said.

Walter Roberson
on 8 Mar 2012

At my workplace we often build 3D MRI images from 2D MRI slices. MATLAB is okay for displaying the resulting datasets if you just want a planar slice, but it is far far below the 3-space imaging capabilities of some other products.

For example see

http://www.vitalimages.com/App_Themes/VitalStandard/Images/Common/04-HPHOTO.jpg

and look at the lower-left image in the "screen" in the middle foreground. Textured, shaded, cut-ins, real-time transparency control based upon data ranges so that you can see (e.g.) tumors and peer inside them...

Image Analyst
on 8 Mar 2012

I definitely agree that MATLAB doesn't have anywhere near the power of other programs in doing volumetric visualization.

Log in to comment.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 10 Comments

## Doug Hull (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_67205

What does it mean to convert a 2-d image to 3-d?

## Sean de Wolski (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_67206

@Doug, repmat() it!

## Med_Imager (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_67209

Do you just want to add a dimension?

MRI_3D=repmat(MRI, [1 1 64])

if there is a whole bunch of images you could run a for loop

## Med_Imager (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_67210

However, your question is confusing, if you say you have 2D IMAGES (plural)

that means it is something like a 3D

size(horizontal) x size(vert) x # of images

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_67216

Question for Maha: are your images already registered, or do you need to do the registration step?

If the source images are in DICOM format from a standard MRI machine, and are from a single scan, then you can assume they are registered relative to each other. It won't be completely true, but it should be close enough for brain imaging (but will _not_ be close enough for chest imaging!)

If the source images are averaged from multiple scans, or are from multiple modalities, then you will need to do image registration.

## maha mohy (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_67364

thanks all,@ Mr Walter I don't think they are registered cuz I extracted them from reference ,so what will I do to register them

## sorena mirzaie (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_153027

try gray2rgb

## Bhoomika Ghosh (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_163075

@i have a similar project currently i have registered images from DICOM and need an algorithm / code to convert 64 slices into a 3D brain model.. can u plz help me! Walter Roberson

## zee falcon (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_416491

I also need help for 3d conversion of MRI images. Need code to convert it into 3d model. Kindly help me out.

## Image Analyst (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/31647-how-to-convert-2d-image-into-3d#comment_416531

Explain why cat() did not work for you.

Log in to comment.