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

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

1 Like

Good point @lassoan, I added this 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. I don’t have easy access to the right printer, so it would be great of people who do could help improve the code.

1 Like

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.

2 Likes

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…

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

I don’t think vtkPNGWriter 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)

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.

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 is a document from Stratasys that explains this further.

1 Like

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?

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

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

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)

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

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

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.

You may need to adjust slabSpacing value in BitmapGenerator.py to match your printer’s layer thickness.

1 Like

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.

1 Like

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

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

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