Converting STL file to TIFF stack

Hello,

I am attempting to convert an STL file containing spherical-like particles into a stack of TIFF image files using the code provided by @lassoan in this thread discussion:

I was able to run the code in 3D Slicer’s Python console without any errors (except for a few warnings that I think can be ignored). However, the resulting TIFF images are completely black. Could someone please take a look and help me figure out what might be going wrong?

Warning message:
[VTK] Warning: In vtkSegmentation.h, line 504
[VTK] vtkSegmentation (000001B935AC77D0): vtkSegmentation::SetMasterRepresentationName() method is deprecated, please use SetSourceRepresentationName method instead

I had really appreciate your time and assistance.

Thank you for your support.

Best Regards,
Vinit Nagda

Link to my stl file:

The images are not all black. Outside the spheres pixel values are all 0, inside the pixel value is 255. If you open the image in any scientific imaging software then you will see the difference.

Most consumer image viewers probably scale the entire range of the 16-bit image to the displayed range, so you would barely see the difference between 0 and 255 value. I’ve updated the script now to use 8-bit TIFFs, which basic viewers should be able to handle better.

I would recommend to not use consumer imaging software. Scientific software not just supports larger scalar range but it can also use 3D image file formats, so you would not slow things down by reading/writing hundreds or thousands of files, and you would preserve the 3D image geometry (origin, spacing, axis directions) that you lose when you export to separate slices.