# 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:** 2

<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:** [August 28, 2018, 12:15am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/23 "2018-08-28T00:15:10Z")

</div>

@pieper Should we add this extension to the extension manager? Even if the module is imperfect, it fulfills a need.

---

<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:** [August 28, 2018, 5:09pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/24 "2018-08-28T17:09:07Z")

</div>

Good point @lassoan, I [added this](https://github.com/Slicer/ExtensionsIndex/commit/1f6c8d1b83b1f2830b0613319adfddee73c12b02) as an extension. The extension was generated a while ago but the format should still be good (it builds for me). We can see what it looks like in the morning.

People should feel free to track issues on the [github repository](https://github.com/SlicerFab/SlicerFab). I don’t have easy access to the right printer, so it would be great of people who do could help improve the code.

---

<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:** [August 29, 2018, 9:32pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/25 "2018-08-29T21:32:08Z")

</div>

The SlicerFab extension needed a couple tweaks, but a working extension should be available tomorrow in the extension manager. It could still use work exposing some of the slicing parameters to the in the GUI but it should be workable.

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [October 9, 2018, 4:47am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/26 "2018-10-09T04:47:50Z")

</div>

Does anyone have experience getting the png’s from slicerfab to print at the proper resolutions for a J750? Typically the y -res is 600 the x-res is 300. Currently I do not see an option in the python to modify the resolutions…

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [October 9, 2018, 5:04am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/27 "2018-10-09T05:04:20Z")

</div>

Hi @pieper . Are there any parameters for specifying the x and y resolutions? This is needed to be modified for the printer.

---

<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:** [October 9, 2018, 5:31am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/28 "2018-10-09T05:31:22Z")

</div>

I don’t think [vtkPNGWriter](https://github.com/SlicerFab/SlicerFab/blob/master/BitmapGenerator/BitmapGenerator.py#L180) has an API to set DPI, but you can use Qt’s PNG writer instead:

```
# Grab image from view widget (just to have a complete working example)
lm = slicer.app.layoutManager()
threeDView = lm.threeDWidget(0).threeDView()
renderWindow = threeDView.renderWindow()
threeDView.forceRender()
windowToImage = vtk.vtkWindowToImageFilter()
windowToImage.SetInput(renderWindow)

# Write to file with custom DPI
dpi = 420.0
filename = "c:/tmp/test.png"
windowToImage.Update()
vtkImage = windowToImage.GetOutput()
qImage = qt.QImage()
slicer.qMRMLUtils().vtkImageDataToQImage(vtkImage, qImage)
inchesPerMeter = 39.3700787
qImage.setDotsPerMeterX(dpi*inchesPerMeter)
qImage.setDotsPerMeterY(dpi*inchesPerMeter)
imagePixmap = qt.QPixmap.fromImage(qImage)
imagePixmap.save(filename)
```

---

<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:** [October 9, 2018, 12:30pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/29 "2018-10-09T12:30:11Z")

</div>

Thanks @lassoan

If anyone wants to give this a try, it should be simple to switch to the Qt writer in the code below. Then if it works it would be great to expose this in the GUI.

> <https://github.com/SlicerFab/SlicerFab/blob/master/BitmapGenerator/BitmapGenerator.py#L175-L188>

---

<div class="post-metadata">

**Author:** ![ahmedhosny](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ahmedhosny/32/2272_2.png) [@ahmedhosny](https://discourse.slicer.org/u/ahmedhosny)\
**Post date:** [October 11, 2018, 1:20pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/30 "2018-10-11T13:20:46Z")

</div>

You need to be at 600dpi in the X and 300dpi in the Y for the connex500 printer. Z resolution is at 30um or 0.03mm. Essentially you need the X to be stretched twice as much as the Y. Make sure to do the stretching before the dither, otherwise your bits are not square anymore. Also make sure the X pixels are divisible by 16. crop slightly if needed. Y can be anything. [Here](https://www.dropbox.com/s/lvdjrb2a1q6giql/DOC-08407-A_Voxel-Printing%2B.pdf?dl=0) is a document from Stratasys that explains this further.

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [November 9, 2018, 6:22am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/31 "2018-11-09T06:22:47Z")

</div>

Hey. There seems to be some bugs with the latest SlicerFab. I keep getting a stack of the same image repeated. Its not actually slicing the model anymore. The image is a top down view. How can I fix this?

---

<div class="post-metadata">

**Author:** ![avarghes23](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@avarghes23](https://discourse.slicer.org/u/avarghes23)\
**Post date:** [November 9, 2018, 3:32pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/32 "2018-11-09T15:32:09Z")

</div>

I was able to use the BitmapGenerator yesterday to create a .PNG image stack from a rendered volume by just simply hitting “Apply”. I’m using 3D Slicer 4.11.0 (Nightly Build).

---

<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:** [November 9, 2018, 6:20pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/33 "2018-11-09T18:20:54Z")

</div>

Yes, it worked for me recently too and the code hasn’t changed. Maybe different data or rendering settings?

---

<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:** [November 10, 2018, 5:24am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/34 "2018-11-10T05:24:13Z")

</div>

I’ve tried today with Slicer-4.10 and it works well for me, too.

Do you see the image changing on your screen?  
How large is your volume? (slab spacing is set to 0.5mm; if your volume is very large or very small then you might not see much change in the exported images)  
Is the voxel spacing set in mm? (it is, if you imported from DICOM)

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [November 12, 2018, 4:06pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/35 "2018-11-12T16:06:15Z")

</div>

This has been resolved. The issue come about when cropping out the model to a much smaller size. The original bounding box can get messed up. It seems like the best practice is to save out just the volume and then run the bitmap generator on that one volume.

nick

---

<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:** [November 12, 2018, 5:53pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/36 "2018-11-12T17:53:37Z")

</div>

Yes, I would recommend to crop the volume to the desired size using Crop volume module. You can also apply arbitrarily shaped mask using Segment Editor’s Mask volume effect (available in SegmentEditorExtraEffects extension).

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [December 13, 2018, 10:52pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/37 "2018-12-13T22:52:42Z")

</div>

Hi @pieper and @ahmedhosny . I’m exporting a stack from an infant heart that is about 3" tall and only getting 146 png’s. Its coming in to the printer as .157" tall. Is there a setting in the Python for slicerfab that is off? What can I do to modify this correctly.

---

<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:** [December 13, 2018, 11:17pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/38 "2018-12-13T23:17:49Z")

</div>

You may need to adjust `slabSpacing` value in [BitmapGenerator.py](https://github.com/SlicerFab/SlicerFab/blob/master/BitmapGenerator/BitmapGenerator.py) to match your printer’s layer thickness.

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [December 14, 2018, 12:02am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/39 "2018-12-14T00:02:37Z")

</div>

Ah yes there was an extra piece of code in there overriding the typical .027 spacing to .5. I have deleted it on my end and it is working well.

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [December 24, 2018, 6:59pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/42 "2018-12-24T18:59:34Z")

</div>

@willyci where in the code did you place this block to take our the while background? Or has anyone else worked on creating a transparent background?

---

<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:** [December 27, 2018, 4:33am UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/43 "2018-12-27T04:33:44Z")

</div>

I’ve sent a pull request that adds transparency (alpha channel) to the exported images - see [https://github.com/SlicerFab/SlicerFab/pull/8](https://github.com/SlicerFab/SlicerFab/pull/8)

---

<div class="post-metadata">

**Author:** ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)\
**Post date:** [December 27, 2018, 9:15pm UTC](https://discourse.slicer.org/t/export-volume-rendering-as-stack-of-pngs-not-stls/3333/44 "2018-12-27T21:15:17Z")

</div>

Thanks Andras,  
There is one issue that I am finding. The slab spacing UI create does not allow for 0.027mm it does not allow for anything past 0.00 (two places after the decimal. The code looks good, so I am struggling to find the issue.

nick

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

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