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

**URL:** <https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333>\
**Category:** Support\
**Tags:** volume-rendering, 3d-printing\
**Created:** [June 29, 2018, 11:21am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333 "2018-06-29T11:21:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeCrozier](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@JoeCrozier](https://discourse.slicer.org/u/JoeCrozier)\
**Post date:** [June 29, 2018, 11:21am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/1 "2018-06-29T11:21:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [June 29, 2018, 1:31pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/2 "2018-06-29T13:31:18Z")

</div>

> [@JoeCrozier](#):
>
> as a stack of png’s

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.

---

<div class="post-metadata">

**Author:** ![JoeCrozier](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@JoeCrozier](https://discourse.slicer.org/u/JoeCrozier)\
**Post date:** [June 29, 2018, 1:43pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/3 "2018-06-29T13:43:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [June 29, 2018, 1:48pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/4 "2018-06-29T13:48:52Z")

</div>

> [@JoeCrozier](#):
>
> 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?

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](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/7)] . See the paper linked in the post below:

> [@Printing volume renderings in plastic](https://discourse.slicer.org/t/printing-volume-renderings-in-plastic/3017):
>
> A question that comes up on this forum from time to time is why we can’t [just 3D print the volume rendered view](https://discourse.slicer.org/t/save-volume-rendering-as-stl-file/524). We explain that most printers today expect STL surface models and we go into the difference between volume rendering and surface segmentation. I wanted to point out some just published research about new printing techniques that are much closer to directly printing out a volume rendering. These are photographs of 3D prints made using this technique: Here’s our paper that…

---

<div class="post-metadata">

**Author:** ![JoeCrozier](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@JoeCrozier](https://discourse.slicer.org/u/JoeCrozier)\
**Post date:** [June 29, 2018, 2:02pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/5 "2018-06-29T14:02:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 29, 2018, 2:37pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/6 "2018-06-29T14:37:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 29, 2018, 2:38pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/7 "2018-06-29T14:38:17Z")

</div>

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.

> **[GitHub - SlicerFab/SlicerFab: A 3D Slicer Extension for fabrication of...](https://github.com/SlicerFab/SlicerFab)**
>
> A 3D Slicer Extension for fabrication of physical objects - GitHub - SlicerFab/SlicerFab: A 3D Slicer Extension for fabrication of physical objects

-Steve

---

<div class="post-metadata">

**Author:** ![JoeCrozier](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@JoeCrozier](https://discourse.slicer.org/u/JoeCrozier)\
**Post date:** [June 29, 2018, 2:44pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/8 "2018-06-29T14:44:30Z")

</div>

Woohooo!! That’s awesome thank you!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 29, 2018, 2:53pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/9 "2018-06-29T14:53:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 29, 2018, 3:11pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/10 "2018-06-29T15:11:57Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![JoeCrozier](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@JoeCrozier](https://discourse.slicer.org/u/JoeCrozier)\
**Post date:** [June 29, 2018, 3:17pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/11 "2018-06-29T15:17:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 29, 2018, 3:50pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/12 "2018-06-29T15:50:25Z")

</div>

The parameters are here:

> <https://github.com/SlicerFab/SlicerFab/blob/master/BitmapGenerator/BitmapGenerator.py#L97-L103>

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.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 29, 2018, 3:52pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/13 "2018-06-29T15:52:24Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Hamburgerfinger](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@Hamburgerfinger](https://discourse.slicer.org/u/Hamburgerfinger)\
**Post date:** [June 29, 2018, 3:52pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/14 "2018-06-29T15:52:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 29, 2018, 3:58pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/15 "2018-06-29T15:58:38Z")

</div>

> [@Hamburgerfinger](#):
>
> This looks awesome!

Thanks!

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).

> [@Hamburgerfinger](#):
>
> to the “Additional template paths for modules” section? It should then show up as a module in Slicer, yes?

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.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/1/1138ab893c20a3526270684b1ea6797cbf46aad9.png)

---

<div class="post-metadata">

**Author:** ![JoeCrozier](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@JoeCrozier](https://discourse.slicer.org/u/JoeCrozier)\
**Post date:** [July 5, 2018, 2:43pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/16 "2018-07-05T14:43:50Z")

</div>

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:

 ![Capture](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/9/e9e7b9a180b943947d5b489d17a20297e32a10c0.png)

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!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 5, 2018, 10:28pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/17 "2018-07-05T22:28:12Z")

</div>

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.](https://www.liebertpub.com/doi/pdf/10.1089/3dp.2017.0140)

The script for dithering is in [this ipython notebook file](https://github.com/SlicerFab/SlicerFab/blob/master/workflow/150209_bmpWorkflow.ipynb) 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.

---

<div class="post-metadata">

**Author:** ![JoeCrozier](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@JoeCrozier](https://discourse.slicer.org/u/JoeCrozier)\
**Post date:** [July 6, 2018, 12:26pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/18 "2018-07-06T12:26:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 6, 2018, 12:41pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/19 "2018-07-06T12:41:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![willyci](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@willyci](https://discourse.slicer.org/u/willyci)\
**Post date:** [August 10, 2018, 2:32pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/20 "2018-08-10T14:32:12Z")

</div>

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”.

 ![Capture](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/b/3ba9068b4efc55a78f7d70ef124204a3726402f0.png)

* * *

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. )

```auto
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))
				else:
					newData.append(item)

			img.putdata(newData)
			img.save("t_"+file, "PNG")
			continue
		else:
			continue

```

* * *

[Next page](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333.md?page=2)
