Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Converting the grayscale dimension in a 4D dicom image matrix to RGB

Asked by Antonio on 8 Feb 2013

I converted a mha file to dicom format (and got this file: https://www.dropbox.com/s/i0cr2910ie4k5zy/TumorSimOutput2_T1.dcm ) via a Linux utility program (this one: http://manpages.ubuntu.com/manpages/lucid/man1/gdcm2vtk.1.html ) and visualize it via imshow using threedimensional indexing:

    imshow(image_data(:,:,index),'DisplayRange',[]);

when I examine the dimensions of image_data I get:

256 256 1 181

I understand the third dimension is the grayscale intensity (thanks to Walter Roberson and his answer here: http://www.mathworks.com/matlabcentral/answers/62671-4d-dicom-matrix-why-not-3d).

I want to convert this grayscale dimension of the matrix into RGB, how can I do this?

0 Comments

Antonio

1 Answer

Answer by Image Analyst on 8 Feb 2013
Accepted answer

How about extracting the gray scale image from the 4D image, and then converting it:

grayImage = your4Dimage(:,:,1,181); % Can use any frame instead of 181
rgbImage = cat(3, grayImage, grayImage, grayImage);

3 Comments

Walter Roberson on 8 Feb 2013

You can do them all at once with

rgb4DImage = cat(3, your4Dimage, you4Dimage, your4Dimage);

or with

rgb4Dimage = your4Dimage(:,:,[1 1 1],:);
Antonio on 15 Feb 2013

how do I go about displaying it?

index = 45;
imshow (rgb4Dimage(:,:,index),[]);

shows a botched image after the conversion, and if I don't specify the second parameter on imshow, I get a black screen.

Image Analyst on 15 Feb 2013

You don't use [] with an RGB image, only grayscale. But for RGB images, the values have to be between 0 and 1 if the image is floating point, and between 0 and 255 if it's uint8. I suggest you capture that slice into a single 2D image (like Walter suggested) so that you can do "whos" on it to see what class and dimensions it really has, before you just blindly toss it into imshow() and hope for the best. So, now, is your image gray scale, or color, and is it double or uint8?

rgb4Dimage = your4Dimage(:,:,[1 1 1],:);
whos rgb4Dimage 
size(rgb4Dimage)

what does all that show?

Image Analyst

Contact us