AWS Thinkbox Discussion Forums

Creating pointcloud from image stack

I am wondering if there is a way to create a pointcloud from an image stack.

Can this be done from within Magmaflow or are there any 3rd party tools that can combine several thousand voxel slices into one pointcloud?

I can see two major approaches to solving this, but neither is a single-click solution.

  1. Creating meshes with textures and sampling them using a PRT Surface + Magma.
  2. Writing a MAXScript that reads the pixels of the images and writes points using the MAXScript Interface for saving PRTs.

The first approach will be problematic, because Max is not great at managing large numbers of objects with large numbers of materials with thousands of textures - it would be very memory-intensive, and the speed of PRT Surface + Magma would be lost due to the slowness of Max itself.

The second approach should be much more straight-forward, and you can keep the memory usage low by loading one slice at a time, sampling it and releasing the memory before moving to the next slice in a loop, and the PRT saving does not use any memory anyway (it writes one particle at a time).
thinkboxsoftware.com/krak-pa … -mxscript/

If you could email me (bobo AT thinkboxsoftware DOT com) a few slice images (like 10 or so), I could write a quick prototype…

Thanks Bobo… Sample sent via email

For anyone else following this, I tried two things and both worked:

  • In my first test, I wrote a MAXScript that would create a single PRT file from all the slices in a folder. The result was nice, but it took about 12 seconds per 2048x2048 image slice, or 120 seconds for 10 slices. Thus it would require nearly 7 hours to convert 2048 slices to a PRT.

  • In my second test, I wired a PRT Maker with a Magma that

  • distributes the points in a 2D grid with size 2048x2048, and moves the Z up based on the current frame

  • samples the texture at UVs = Position/2048 and sets the Color, Density and the Selection channel to delete any black particles.

  • I then saved a PRT sequence so that each slice would be written to its own PRT file.

  • Finally, I loaded all the PRTs as individual lines in a PRT Loader set to Single Frame Only, and I got the volume of points where the slice had non-zero color pixels.

The second approach took about 2 seconds per frame (mostly spent evaluating the texture), so it would process a stack of 2048 images in about an hour and a few minutes…

I will post more details as this comes along.

Interesting stuff! Medical applications, I guess :slight_smile:

Color/image/visual level set! Cool :slight_smile:

Actually it was for a Mandelbulb, but it could be used for medical applications too…

Hi Bobo,

I stumbled across this thread while I was looking for an easy solution to convert image stacks coming from Mandelbulb into a file format we can read in 3ds Max. Right now we are considering an approach where we use OpenImageIO and OpenVDB to covert the data. I was wondering if your prototype is somewhere available. Any further help is greatly appreciated.

Thank you,
Christian

Sure, no problem.

I modified the example setup I had prepared to use a 3D procedural texture (Cellular) in place of the image stack bitmapTexture, but the actual Krakatoa + Magma setup remains the same. I even improved it a bit.

In this scene, you have a PRT Maker which currently generates a grid of 512x512 samples via the Magma on top of it. The number of particles generated in the PRT Maker must be greater or equal to the square of the Resolution requested. So right now I have 262144 particles generated and distributed, but if you want to generate 1024 or 2048 samples, you will have to increase the count in the base object to 1048576 or 4194304 respectively.

In the Magma, a texture map is loaded in the InputTexture operator and is sampled in UV space. The map I have set is actually in Object Space, but it still works. The texture color is output as Color, its Magnitude is output as Density, and a Selection channel is set based on a Threshold value which can be tweaked to erode the darker parts of the image with a Krakatoa Delete on top of the stack.

To use with an Image Stack, simply create an IFL sequence of the images and load one image per frame using a BitmapTexture assigned to the InputTexture node in Magma. As you advance the time line, the next image will be loaded and sampled. Then you just save N frames to PRT using Krakatoa, and each frame will contain the particles generated from each slice, shifted up one unit for each frame.

You can then select the saved PRT files in Windows Explorer, hold SHIFT, right-click, select Copy As Path to put all file names into the Windows Clipboard.
Create a PRT Loader, and use its [>>] options menu to paste from clipboard and load all frames as partitions, thus generating a 3D block of slices. Check “Load Single Frame Only” to ignore the frame numbers in the files.

Attached is a Max 2013 version of the file (created in 2015) that shows the basics. Please let me know if you have any questions.
KMX2_SampleImagePlanes_CellularDemo_v001.zip (29.9 KB)

Thank you very much! I will give it a try and get back to you.

Christian

Privacy | Site terms | Cookie preferences