How do I convert a 3D greyscale image into a 2D greyscale image?
Mostra commenti meno recenti
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
Risposte (2)
Image Analyst
il 20 Giu 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 Commenti
D Overduin
il 20 Giu 2021
Walter Roberson
il 20 Giu 2021
No. It is more like
P(I, J) = max(Img(I, J, :))
This would model a fully transparent light emitting object where for any particular pixel what you perceive is the brightest pixel in that direction.
Walter Roberson
il 20 Giu 2021
And not, for example, a fully transparent light emitting object where for any particular pixel what you perceive is the total light in that direction.
Walter Roberson
il 20 Giu 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
il 20 Giu 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
il 20 Giu 2021
0 voti
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 Commenti
D Overduin
il 20 Giu 2021
Modificato: D Overduin
il 21 Giu 2021
Walter Roberson
il 20 Giu 2021
Okay, so what value or range indicates transparent?
Walter Roberson
il 20 Giu 2021
zc = sum( cumprod( grayImage3d~=0, 3), 3);
zc is now the count, 0 to 16, of the number of 0's before the first non-zero entry. 0 would mean that grayImage3d(I, J, 1) is nonzero, and 16 would mean that all of the pixels at (I, J, :) are zero. And this means that if the count is not 16, then (I, J, count+1) is the content of the first nonzero pixel (and if it is 16 then the pixel should be transparent)
Now that you know which layer is the first nonzero, you can extract those pixels into an array.
Image Analyst
il 20 Giu 2021
What do you mean by "The unoccupied space (filled, for example, with air) is opaque"? This is not usual. Usually, like in CT or MRI images, air is transparent (low signal), and tissue is opaque with a much higher signal (gray level).
Do you want it to be like you're looking straight down the z axis and the color in your 2-D image is the color of the first, non-air voxel you encounter? Kind of like you were looking at the "thing" as you held it in your hand or stood over it lying on the ground and looked down on it.
D Overduin
il 21 Giu 2021
Image Analyst
il 21 Giu 2021
Modificato: Image Analyst
il 21 Giu 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.
Categorie
Scopri di più su Lighting, Transparency, and Shading in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!