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


(Andras Lasso) #23

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

(Steve Pieper) #24

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.

(Steve Pieper) #25

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.

(Nick) #26

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…

(Nick) #27

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

(Andras Lasso) #28

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()
windowToImage = vtk.vtkWindowToImageFilter()

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

(Steve Pieper) #29

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.

(Ahmed Hosny) #30

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.

(Nick) #31

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?

(Anish ) #32

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

(Steve Pieper) #33

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

(Andras Lasso) #34

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)

(Nick) #35

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.


(Andras Lasso) #36

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

(Nick) #37

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.

(Andras Lasso) #38

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

(Nick) #39

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.

(Nick) #42

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

(Andras Lasso) #43

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

(Nick) #44

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.