# Problem in slicing a stl file to tiff/PNG/jpeg stack

**URL:** <https://discourse.slicer.org/t/problem-in-slicing-a-stl-file-to-tiff-png-jpeg-stack/16179>\
**Category:** Support\
**Tags:** segmentation, python\
**Created:** [February 24, 2021, 1:38pm UTC](https://discourse.slicer.org/t/problem-in-slicing-a-stl-file-to-tiff-png-jpeg-stack/16179 "2021-02-24T13:38:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehrdad](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mehrdad](https://discourse.slicer.org/u/Mehrdad)\
**Post date:** [February 24, 2021, 1:38pm UTC](https://discourse.slicer.org/t/problem-in-slicing-a-stl-file-to-tiff-png-jpeg-stack/16179/1 "2021-02-24T13:38:11Z")

</div>

Dear Support Team,

I have stl file of packing of angular particles. The cubic packing size is 400 voxels and the voxel size is 0.03111 mm. I need to convert the stl file to the tiff stack with 400 slices and a pixel size of 0.03111 mm. I have tried the python script provided by the team in 3d slicer ([Convert STL file to high-resolution TIFF stack - #8 by lassoan](https://discourse.slicer.org/t/convert-stl-file-to-high-resolution-tiff-stack/15949/8)) but didn’t get the correct result. It just gave 2 slices after 1 hour and the slices just include a single black point.  
I need to know what values should I use in the following parts:  
outputVolumeLabelValue, inPlaneResolutionDpi, planeThicknessMm, outputVolumeMarginMm

How would you calculate 25.4 in the following part? What values should I use for my packing?  
imageSpacingMm = [25.4/inPlaneResolutionDpi, 25.4/inPlaneResolutionDpi, planeThicknessMm]

I look forward to hearing back from you.

Kind regards,  
Mehrdad

---

<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:** [February 25, 2021, 6:34pm UTC](https://discourse.slicer.org/t/problem-in-slicing-a-stl-file-to-tiff-png-jpeg-stack/16179/2 "2021-02-25T18:34:17Z")

</div>

If you have your image spacing defined as mm/pixel instead of inches/pixel (DPI) then you can set that directly in imageSpacingMm. 0.03111mm/pixel = 0.0012248 in/pixel =\> 816 pixel/in (DPI), so the default 400 DPI should be OK, but just for initial testing you can try lower resolution (40DPI).

How many points does your STL file contain? Can you share the file so that I can test it?

---

<div class="post-metadata">

**Author:** ![Mehrdad](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mehrdad](https://discourse.slicer.org/u/Mehrdad)\
**Post date:** [February 26, 2021, 12:02am UTC](https://discourse.slicer.org/t/problem-in-slicing-a-stl-file-to-tiff-png-jpeg-stack/16179/3 "2021-02-26T00:02:01Z")

</div>

Hi Lassoan,

Thanks for your advice. What value should I use for outputVolumeLabelValue and outputVolumeMarginMm?

Should imageSpacingMm be [0.03111, 0.03111, 0.03111] in my case?  
planeThicknessMm=0.03111?  
inPlaneResolutionDpi=400?

How should I share the stl file? I could not attach the stl file.

Thanks for your help. I look forward to hearing back from you.

Kind regards,  
Mehrdad

---

<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:** [February 26, 2021, 3:57am UTC](https://discourse.slicer.org/t/problem-in-slicing-a-stl-file-to-tiff-png-jpeg-stack/16179/4 "2021-02-26T03:57:28Z")

</div>

> [@Mehrdad](#):
>
> outputVolumeLabelValue

Whatever non-zero value you would like to see in the image inside the model.

> [@Mehrdad](#):
>
> Should imageSpacingMm be [0.03111, 0.03111, 0.03111] in my case?  
> planeThicknessMm=0.03111?  
> inPlaneResolutionDpi=400?

Yes, set `imageSpacingMm=[0.03111, 0.03111, 0.03111]` directly and remove the now redundant `planeThicknessMm` and `inPlaneResolutionDpi` variables.

> [@Mehrdad](#):
>
> How should I share the stl file? I could not attach the stl file.

Upload to somewhere (dropbox, onedrive, google drive, …) and post the link here.
