How do I convert a 3D greyscale image into a 2D greyscale image?
6 views (last 30 days)
Show older comments
Hi all,
I have 140 x 160 x 16 greyscale image of a single object. Each image along its z-axis (length is 16) is slightly different as it traverses the depth of the object. How do I convert this 3D image into a 2D image? Please note, that I would like obtain an image as if the original image have been compacted to a single slice (i.e. z-axis length is 1) by pressing down on the x-y plane of the original image.
Thank you!
All best
0 Comments
Answers (2)
Image Analyst
on 20 Jun 2021
There are several things you can do that are typically done. One is to get a mean projection along the slices, where you take the mean value along each vertical column of pixels.
meanSliceImage = mean(grayImage3d, 3);
The other is to get a max projection, where you take the max along each vertical column of pixels.
maxProjectionImage = max(grayImage3d, [], 3);
Or you can simply extract a slice. For example to get slice #9 you could do
slice9 = grayImage3d(:, :, 9);
5 Comments
Walter Roberson
on 20 Jun 2021
You have to take into account: is it a light emitting object, in which the different spots are different inherent brightness? Is it a light emitting object in which the different spots are all the same inherent brightness but the material might have variable opaqueness? Is it a light reflecting object in which the source lights are different brightness but the surface is consistent reflectively? A light reflecting object in which the surface is variable reflectivity (which is the situation for most coloured solids)? If reflecting is the reflection only from the surface, or is it semi-transparent and the light is being absorbed and scattered back internally?
Your output would be very different if you are modelling a block of concrete than if you are modelling mica or if you are modelling a Snow Globe.
Image Analyst
on 20 Jun 2021
If you have a volumetric image, imagine it as a rectangular block, and you stomped on the top of it to crush it into a 2-D image.
Each column of the 3-D image, not to be confused with a column from the 2-D image, collapses into a single pixel in the 2-D image, and it's value would be either the max value in that vertical column, or the mean value, depending on what you chose.
Or if you chose a single slice, it would be like taking two horizontal slices through your block and pulling out the slice in between the cuts.
But rather than asking "What can be done?" you should already know what you need to do and should be asking "How can I obtain that?" Don't just take some arbitrary random suggestion someone makes because it probably won't solve the problem that you ultimately need to solve.
Walter Roberson
on 20 Jun 2021
There isn't just one solution.
If you think of the data as a solid opaque object being viewed from parallel to an axes, then the task becomes a simple matter of indexing the first or last pane along x, y, or z.
But perhaps you are viewing it from iindefinitely far, but from an angle, then you need to apply a rotation matrix to the coordinates and then find the closest part of the object in a given direction to retain and drop the rest in that direction. (See also Projection Matrix)
You use the same basic technique if you are viewing from a point instead of from a direction.
Then there is also the possibility that the object should not be considered completely solid. In that case, you need the rotation matrix type approach but you also need Alpha Blending to calculate the net colour (brightness) perceived.
A different approach that is used, especially for more complex scenes, is Ray Tracing.
6 Comments
Image Analyst
on 21 Jun 2021
Edited: Image Analyst
on 21 Jun 2021
So did either of us suggest something that ended up working (doing what you wanted)? If so, please accept that Answer (you can accept only one). Thanks in advance.
See Also
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!