- Home /
How to Volume Render from a Stack of 2D Slices and (Possibly?) Generate a Mesh?
I am looking to render a volume using a stack of 2D images, such as MRI data, and possibly generate a mesh from that data. Methods I have looked into for volume rendering with Ray Marching typically result in a volume not calculated in world space. I would need the object to render in World Space with other meshes woven in the semi-transparent volume, meaning setting a static render layer would not solve this to my knowledge.
Would it be possible to analyze the 2D image stack and create a mesh / detailed voxel mesh from the RGBA data, given the layer spacing?
Any information on techniques that would guide me towards an answer such as in-depth how-to for ray-marching for world-space rendering in Unity or efficient 3D mesh rendering from 2D image stacks would be greatly appreciated (the mesh generation does not need to be done at run-time on a build but the mesh would need to be saved out).
I apologize for ignorance on the details of the methods used to accomplish what I want to do and the terminology in advance but I am trying to explain in depth what I am trying to accomplish.
Thank you!
I don't know how ray-marching would help. I'd just go through each image (I suppose it's a Texture type) and then go through each pixel via GetPixel, and if the alpha value of the color is above 0, treat it as a solid space. Simultaneously, create a 3-dimensional int array that corresponds to the image sizes with the y dimension as the number of image layers.
Go through each cell in the array and if a cell is solid and check it's neighbors. If one is also solid, add the vertices of a face for that cube side to the mesh's vertex array.
It's basically how all the $$anonymous$$inecraft clones work. Basic voxel stuff.
Interesting, this follows what I have been looking into but few, if any, examples out there have dealt with image stacks (you are right, 2D textures (RGBA)) and have shown the fidelity I have needed. Are their any sources you could point me towards that would help me with examples? This is something that will be viewed from all angles, moved by the user, and clipped into so interior values/space matters, a Boolean approach will not necessarily work since there will be some variance of alpha with the medical image stacks.
Edit: I realize the second half of my reply is to the volumetric visualization in scene and not the mesh generation but the mesh generation based on values between 0 and 1 versus >0 would be very different right? Thresholds between 0 and 1 that generate varying meshes would be an interesting approach but I am not sure how to go that route.
A source I found for Voxel $$anonymous$$esh: http://alexstv.com/ and the older posts: http://studentgamedev.blogspot.com/2013/08/unity-voxel-tutorial-part-1-generating.html
The only thing you need to know is how to generate meshes from script, which is information that can be obtained from the Scripting API ($$anonymous$$esh class). Then it's just a matter of taking your 3-dimensional array and deciding wether a cell that is solid has any of the six possible faces that make up a cube.
Have you found out how to have a volume rendered 3D Texture interact correctly with other meshes? I'm currently struggling with this problem.
Answer by mezzostatic · Jan 04, 2017 at 12:39 PM
Im working on something similar, i am coding point clouds from stacks of images to process them in a point cloud program or meshlab. edge detection depends on the image you start from, if it is BW or color, you have to decide what criteria you want.
then march along the top and bottom image, get all the pixels that represent an volume, then march through all the other layers and race through the edges and check out what pixels you want from there inthe point cloud/mesh and then march through the images themselves detecting every color which changes from B/W as a border or which is a certain shade as a threshold where vertices can be.
i've finished a code in BW, it's about 5 7 hours work i can send it along for 10 dollars i have my bank nagging me. regards.
Answer by ceitel · Aug 30, 2017 at 07:23 PM
@Izaaner If it does not need to be done at run-time I would suggest freeware such as 3DSlicer (https://www.slicer.org/) which lets you do everything you've mentioned and save to an OBJ or STL file. If it needs to be done at run-time in Unity I'm still searching for an answer to this.