# How to substract two STL files?

**URL:** <https://discourse.slicer.org/t/how-to-substract-two-stl-files/31888>\
**Category:** Support\
**Created:** [September 25, 2023, 2:49pm UTC](https://discourse.slicer.org/t/how-to-substract-two-stl-files/31888 "2023-09-25T14:49:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inka\_Saraswati](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/inka_saraswati/32/67631_2.png) [@Inka\_Saraswati](https://discourse.slicer.org/u/Inka_Saraswati)\
**Post date:** [September 25, 2023, 2:49pm UTC](https://discourse.slicer.org/t/how-to-substract-two-stl-files/31888/1 "2023-09-25T14:49:54Z")

</div>

I have 2 STLs, one is a model of bone with defect, the other one is an intact one. I want to get a 3D model of the defect (the difference between the two files). I know how to substract with Logical Operators in Segment Editor, but I believe it only works if I did a segmentation from volume data (such as CT) in the Slicer itself. I want to be able to import 2 STLs and substract them. How to do it in Slicer?

Thank you!

---

<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:** [September 25, 2023, 3:06pm UTC](https://discourse.slicer.org/t/how-to-substract-two-stl-files/31888/2 "2023-09-25T15:06:26Z")

</div>

You can load the two STLs as segmentation and use the logical operators as you describe. But depending on where they came from they probably won’t line up correctly. So you need to first register them either manually or with a [model registration](https://slicer.readthedocs.io/en/latest/user_guide/registration.html#model-registration) tool. This can be challenging when parts are missing from one of the bones, but you should be able to get a good approximation.

---

<div class="post-metadata">

**Author:** ![Inka\_Saraswati](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/inka_saraswati/32/67631_2.png) [@Inka\_Saraswati](https://discourse.slicer.org/u/Inka_Saraswati)\
**Post date:** [September 26, 2023, 2:04am UTC](https://discourse.slicer.org/t/how-to-substract-two-stl-files/31888/3 "2023-09-26T02:04:31Z")

</div>

I’ve done registration with SlicerIGT (still not perfect but I just want to try the features for now). I’ve tried 2 things that didn’t really work.

1. This one I’ve imported the two STLS as models, and all of the Segment Editor is greyed out. My models did not appear in the Segmentation list.  

2. I’ve also tried importing the two STLs as segmentation. My data did appear in the Segmentation list in the Segment Editor, but I can only choose one or the other. And all the buttons on the left are also greyed out, including Logical Operators.  

What should I do so I can substract them?

---

<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:** [September 27, 2023, 11:41pm UTC](https://discourse.slicer.org/t/how-to-substract-two-stl-files/31888/4 "2023-09-27T23:41:45Z")

</div>

You probably need to import one of the CT scans too so the segment editor has a reference volume, then you can edit. Use the Segmentations module to copy a segment from one segmentation to the other.

---

<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:** [September 28, 2023, 2:02am UTC](https://discourse.slicer.org/t/how-to-substract-two-stl-files/31888/5 "2023-09-28T02:02:55Z")

</div>

Loading the original CT as @pieper suggested is the best, as it allows you to verify that all segmentation operations are sufficiently accurate. Alternatively, you can create a default blank volume as described in the [documentation](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentations.html#editing-a-segmentation-imported-from-model-surface-mesh-file).

Your segmented surfaces look very noisy. You could consider smoothing it before doing any other operation. Also, volumetry is not appropriate for compatison when you work with very thin structures as we can see in your image. Instead, you can measure surface-to-surface distance (using ModelToModelDistance extension) or you can fill in cavities and work with solid objects (using [SurfaceWrapSolidify extension](https://github.com/sebastianandress/Slicer-SurfaceWrapSolidify#surface-wrap-solidify)).
