Export Volume Rendering as stack of PNG's. NOT stl's

Operating system:Windows 10 Pro
Slicer version:4.9.0

Hello. I did a quick google search but nothing showed up so I was wondering if you could help me.

I am very familiar with thresholding/segmenting/exporting as stl’s, etc… I work as a 3d Printing Lab Coordinator at a hospital.

However I’m fortunate enough to have a printer that can print voxel by voxel and theoretically have MUCH more detail than traditional 3d printers (in 500,000+ colors). In order to print at the voxel level I need to provide a stack of .png’s to the software. Obviously my first thought was to take the dicom images and convert to png in batch and provide that, but I’d rather not just have black and white prints. So I thought it’d be cool if the volume rendering options in 3d slicer that provide color volumes could then be exported (with their colors) as a stack of png’s. Possible? How do I do it?

Thank you for any help!

You may record a video from your VR model using Screen Capture module, then export each frame to PNG images. It should be possible to modify the ffmpeg video creation options so that the source PNG files are not deleted during video creation, but I don’t know what other option to pass to ffmpeg. Or I completely missed your point.

I’d have to try it but I’m not 100% sure thats it. What I’m looking for is really just like a png that is a colorized version of each dicom image. I know there are dicom-> png converters (which i’ve used) but then I’m left with black and white png’s. I want pngs that have color and transparency added in a similar manner to what the volume render did. I can then send that stack of png’s to my printer.

I’m assuming pngs from the video would be more like a frame by frame screenshot from one viewpoint? Right?

1 Like

This is still an area of active research, and I don’t believe there is any turnkey solution implemented in Slicer right now [edit: see link below] . See the paper linked in the post below:

1 Like

Thank you. I had kind of assumed it wasn’t in slicer yet but I wanted to double check. I know just enough programming in R to be dangerous and I think I’ll tinker with creating my own converter for dicom-> png with added color. We’ll see if I’m in over my head.

What is the input to your printer? A 3D array of RGB voxels?

Hi Joe -

Actually there’s a working prototype we started a while back. I just tested it and it works with Slicer 4.8 and may be just what you are looking for. Hope it works for your purposes.



Woohooo!! That’s awesome thank you!

Steve, what kind of data your printer takes as input? 3D volume of dithered binary voxels, or RGB voxels?

@lassoan it’s the one described in the paper - it acts just like an inkjet printer where you can choose what to deposit at each point (mix of primitive colors CMYK plus clear and maybe others like something to control the stiffness of the material). There’s dithering in the driver to map the continuous tone of the input images to essentially bitmap (on/off) at high resolution of the printer. So these sliced PNGs essentially go right into the printer driver. That’s why the main module is called the BitmapGenerator.

By the way, it would be great if anyone wants to enhance this SlicerFab code. There are more parameters like slab thickness and spacing, output image resolution, and other things that could easily be added to the interface if needed.

1 Like

I just installed it and used it to generate png’s. Prior to sending to the printer I should double check layer height. The j750 I use has a 0.027mm thickness between layers, and I know the one in your paper was listed at 0.030. Does the BitmapGenerator module automatically reslice to create this 0.030 thickness?

The parameters are here:

If you know the values you want, I’d suggest changing them in the code and then restarting slicer. If you find yourself experimenting, you can enable Developer Mode in Slicer (se Edit->Application Settings -> Developer) and you’ll get a Reload button so you can change the code on the fly.

Longer term, as I mentioned, it would be good to expose these in the user interface, possibly with presets for any commonly used printers.

1 Like

I should mention too that this isn’t exactly the code used in the paper - some of the authors worked on this as a way to generalize the scripts used for the paper.

At this point there haven’t been a lot of prints made, so the best mapping between volume rendering and printer files is a bit of an open question (input welcome).

1 Like

This looks awesome! I tried to install it as an extension via Slicer’s Application Settings–>Extension Wizard but it seems to not be working… All that I have to do is add the path to the BitmapGenerator folder (in the SlicerFab-master folder cloned from GitHub) to the “Additional template paths for modules” section? It should then show up as a module in Slicer, yes?


Right - this is not in the Extension manager yet, but the structure is compatible, so if we confirm it works well and maybe add some tweaks to the UI it would be easy to migrate it (this would make it easier to install).

You can either put the path on the command line as in the README of the repository or you can add it to the Edit->Application Settings dialog by clicking the Add button shown below and browsing to the BitmapGenerator folder and then restarting.

Again, thank you for pointing out these modules. Being close by I’d love to come up and talk to you about this in person.

My question now pertains to using this module to export png’s in color for the j750. My contact at grabcad sent me this in response to the png’s SlicerFab created:

In your experience is there a way to control the number of colors exported? Either in the volume rendering itself or in the code of slicerfab?

Thank you!

Right - the SlicerFab module just puts out the continuous tone color files, but they need to be further process for the printer using the dithering technique described in the paper.

The script for dithering is in this ipython notebook file but doesn’t run automatically. This allows you to get full color in the print even with a small number of colors in the printer (just like an ink just printer can print color images with only 4 ink cartridges).

Integrating the dithering step into the module directly is another task we haven’t had a chance to do yet, which is another reason SlicerFab is not a regular Slicer extension yet.

1 Like

Guess I should have “read the manual”. Thank you!

It’s definitely a work-in-progress so let us know how it goes for you!

Just want to say thanks to you guys, this module help me a lot, easy to use.

I am new to slicer, if anyone like me having problem using it, here is what I did
I am on V4.8.1
goto edit --> app setting
in modules, add the folder where the py code it. restart the app, it should show up in the modules drop down
once you got the volume rendering setup, open the BitmapGenerator, setup where the folder is, click on “Apply”.

I need the image to to be transparent , but I don’t know much about python,
so here is my python code to remove the white background.
( maybe someone can update the module’s scode. )

import os
rootdir = '/temp/'
extensions = ('.png')
from PIL import Image

for subdir, dirs, files in os.walk(rootdir):
	for file in files:
		ext = os.path.splitext(file)[-1].lower()
		if ext in extensions:
			print (os.path.join(subdir, file))
			img = Image.open(file)
			img = img.convert("RGBA")
			datas = img.getdata()
			newData = []
			for item in datas:
				if item[0] == 255 and item[1] == 255 and item[2] == 255:
					newData.append((255, 255, 255, 0))

			img.save("t_"+file, "PNG")

1 Like