How can i convert a 3D image to 2D in matlab?

109 views (last 30 days)
dee koshy
dee koshy on 20 Feb 2012
Commented: Mihirasree on 9 Nov 2022
I am using a code that will work only on 2D arrays and I have to convert the current image which is in 3D to 2D.

Answers (2)

Image Analyst
Image Analyst on 20 Feb 2012
Edited: Image Analyst on 28 Feb 2014
If the 3D image is a color image, you can take individual color channels like this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Or you could use a weighted average of the red, green, and blue channels like this:
grayImage = rgb2gray(rgbImage);
Or if you have a volumetric image (like a CT or MRI image or other image distributed in 3 spatial dimensions) you can use the mean (or max or min) like this
xyImage = mean(volumeImage, 3);
xzImage = mean(volumeImage, 2);
yzImage = mean(volumeImage, 1);
They will get you the average of the 3D volumetric image projected along one of the dimensions.
  7 Comments
Mihirasree
Mihirasree on 9 Nov 2022
thank you soo much sir your suggestions helping us all a lot . Thanks for helping us

Sign in to comment.


Dinesh kumar
Dinesh kumar on 13 Nov 2016
please answer me the coding for how to convert a 3d image into 2d image
  4 Comments
Galiyabi P S
Galiyabi P S on 29 Jan 2017
Thanks Walter Roberson for your answer. It helps me to read and display the mha image. Can you help me to convert these images to rgb format?

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!