# Segmented, exported surfaces overlap (unexpected)

**URL:** <https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012>\
**Category:** Support\
**Created:** [November 24, 2023, 7:56pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012 "2023-11-24T19:56:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [November 24, 2023, 7:56pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/1 "2023-11-24T19:56:56Z")

</div>

I first segmented the bone (green), then I painted the yellow-browinsh segment without allowing overlap with the green one.

 ![Captura de pantalla 2023-11-24 163632_2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/d/0d06fa6e8a52a88ad1ea2bab02b46e14bb56920c.jpeg)

When I did “export visible segments to models”. The 3D models of the segments _ **do** _ overlay. Check this image:

 ![Captura de pantalla 2023-11-24 163709_2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/1/417ba177c33addd418bae190864ce5097b332355.jpeg)

This is unexpected. Is it a bug?

I’m using Slicer 5.2.2 stable release

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [November 27, 2023, 9:25pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/2 "2023-11-27T21:25:12Z")

</div>

Could someone comment on this?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [November 27, 2023, 10:19pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/3 "2023-11-27T22:19:04Z")

</div>

I suspect this is due to each segment being smoothed independently in the conversion to the closed surface representation. In the Segmentations module, click the dropdown next to “Closed Surface” to access and modify the conversion parameters.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/6/6629803a743fb04d8c98ed0560a9cb90b541aead.png)  
This will raise the following window:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/5/1581a1b70ebd9e6030d66ab143e7396b09340222.png)  
Click on the conversion path step (the line in the upper section), and then try changing the Joint smoothing flag to 1.

I tried a quick search in the documentation to see if I could find a reference to this, but didn’t find anything. However, I think this should do what you want.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [November 27, 2023, 10:47pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/4 "2023-11-27T22:47:52Z")

</div>

Thanks for the answer. I’ll check and get back

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [November 28, 2023, 2:01pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/5 "2023-11-28T14:01:13Z")

</div>

Your source representation (i.e. the one that you can consider most faithful to the real world object) is binary labelmap. When you convert these labelmaps to closed surface, then by default you apply smoothing. If the artifacts you get from smoothing are undesired, then you can always disable smoothing.

In that case, however, you get a surface that consists of blocks and it cannot be rendered nicely. Another thing you can do is supersample the segmentation’s binary labelmap, so that it has a higher resolution than the anatomical image. Then you may do less smoothing when you do the conversion to reduce the artifacts you do not want.

You can read very briefly about representations here:  
[https://slicer.readthedocs.io/en/latest/user\_guide/image\_segmentation.html](https://slicer.readthedocs.io/en/latest/user_guide/image_segmentation.html)  
In a bit more detail:

> **[Polymorph segmentation representation for medical image computing](https://scholar.google.ca/citations?view_op=view_citation&hl=en&citation_for_view=LbnADQ0AAAAJ:qUcmZB5y_30C)**
>
> C Pinter, A Lasso, G Fichtinger, Computer methods and programs in biomedicine, 2019 - Cited by 63

In even more detail:  
[https://qspace.library.queensu.ca/handle/1974/26422](https://qspace.library.queensu.ca/handle/1974/26422)

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [November 28, 2023, 5:33pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/6 "2023-11-28T17:33:15Z")

</div>

Hi @mikebind, thanks for your answer

I did not notice any change by using “Joint smoothing” and exporting the models together (there is still collision between the extracted meshes)

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [November 28, 2023, 5:36pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/7 "2023-11-28T17:36:57Z")

</div>

Thanks a lot for your answer @cpinter

I’ll read more about links you provided on weekend since this is only for a feature of a side-project I have

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [November 28, 2023, 6:04pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/8 "2023-11-28T18:04:22Z")

</div>

Thanks for the detailed references @cpinter! Since it looks like you are the expert on this, can you describe what the “Joint smoothing” parameter does in the conversion, if it is not ensuring that touching surfaces do not overlap?

---

<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:** [November 29, 2023, 12:04am UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/9 "2023-11-29T00:04:23Z")

</div>

@mau_igna_06 it would be good if you could try the [JointSmoothing option from the older ModelMaker](https://slicer.readthedocs.io/en/latest/user_guide/modules/modelmaker.html#:~:text=Joint%20Smoothing%20(JointSmoothing)%3A%20This%20will%20ensure%20that%20all%20resulting%20models%20fit%20together%20smoothly%2C%20like%20jigsaw%20puzzle%20pieces.%20Otherwise%20the%20models%20will%20be%20smoothed%20independently%20and%20may%20overlap.). That mode was specifically added to provide watertight boundaries because the vertices of both models were moved identically during the smoothing process, so there was never any gap between the meshes for adjacent segments. There may still be some aspects of the older code that need to be incorporated in the segmentations infrastructure.

This topic has come up before, but it’s still not clear to me that we can easily get the same output meshes that we get with ModelMaker.

> [@surface rendering of many segments](https://discourse.slicer.org/t/surface-rendering-of-many-segments/4044/4):
>
> We have that option in Smoothing effect but not in the automatic conversion between segment representations. The assumption is that smoothing operation in “binary labelmap to closed surface” conversion is only used for removing staircase artifacts and so it does not require adjustment of the geometry. We would need to implement some new mechanism in segmentation infrastructure to allow joint conversion of multiple segments, because right now conversion happens segment by segment.

> [@Exported STL files from the segmentation has intersection/penetration](https://discourse.slicer.org/t/exported-stl-files-from-the-segmentation-has-intersection-penetration/6692):
>
> Operating system: Windows 10 Slicer version: 4.10.1 Hi everyone, I want to create models for mandible and teeth from a CBCT scan. After importing the DICOM file to 3Dslicer and completing the segmentation process I used segmentations/export to export the segmentations as STL models. Then I import those STL files into Meshmixer and I found out the models have intersections! (the surface of the teeth model penetrates the surface of the bone model as you can see in the image). I noticed that 3D …

> [@Exported STL files from the segmentation has intersection/penetration](https://discourse.slicer.org/t/exported-stl-files-from-the-segmentation-has-intersection-penetration/6692/9):
>
> @Tekk_ya you might try a slightly different pathway to get “watertight” models. export the segmentation to a label map run the ModelMaker module with the “Joint Smoothing” operation enabled what this will do is apply the same smoothing operation to matching vertices from the different segments so that no gaps are introduced. In the example below the yellow/green surfaces use the default and the red/blue use Joint Smoothing. @lassoan I don’t see that the segmentation closed surface option ex…

---

<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:** [November 29, 2023, 12:36am UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/10 "2023-11-29T00:36:23Z")

</div>

By enabling “Joint smoothing” option in segmentation conversion parameters, we perform the exact same algorithm as in the Model maker module. The only difference is that it is performed for each layer. If your segments are non-overlapping but they are in separate layers (e.g., because you enabled overlap before) then you can collapse them into one layer in Segmentations module’s Layers section.

---

<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:** [November 29, 2023, 4:54am UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/11 "2023-11-29T04:54:19Z")

</div>

If the segments were overlapping then yes, I can see they cannot be made watertight. But I still don’t see that this is the case in the data @mau_igna_06 posted. It will be good to get some clarity on on this.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [November 29, 2023, 10:11am UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/12 "2023-11-29T10:11:19Z")

</div>

I just tried joint smoothing (5.5.0-2023-11-10 r32231 / 48b6d55, Win11), and I found that if smoothing factor is larger than 0, then we lose the triangles.

Btw I never used joint smoothing here in the conversion parameters but I assume that it should work preserving the cells.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [December 9, 2023, 8:34pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/13 "2023-12-09T20:34:16Z")

</div>

Hi

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/2/e2dbb0050016578d5376871fbc735a94a2afde88.png)

I tried all last three options on the dialog, to update the 3D surface of two touching segments on a segmentation, then exported them as models and named the different resulting folders as a binary table (e.g. folder named 100 means it was created using conversion parameters “Joint smoothing”=1, “SurfaceNets smoothing”=0, “Conversion method”=0)

[Download SceneFile](https://file.io/t7pu1SOXR3QA)  
(Done with latest Slicer Preview release from today)

Hope this helps on debugging

---

<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:** [December 9, 2023, 9:09pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/14 "2023-12-09T21:09:40Z")

</div>

> [@mau\_igna\_06](#):
>
> I tried all last three options on the dialog

Where there gaps in all methods?

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [December 9, 2023, 9:17pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/15 "2023-12-09T21:17:46Z")

</div>

No collisions (that is watertightness between segments) was achieved using:  
“Joint smoothing”=0, “SurfaceNets smoothing”=1

The names of the folders that are visible on the earlier picture explain a bit what I found after each export

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [December 12, 2023, 9:16pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/16 "2023-12-12T21:16:10Z")

</div>

Is this considered solved?

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [December 12, 2023, 9:29pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/17 "2023-12-12T21:29:40Z")

</div>

I’m not sure I fully follow all the results here. Is your conclusion that you were only able to achieve non-collision by accepting bad smoothing? That is, there was not a method you found which gave good smoothing results without also introducing overlaps or inappropriate gaps between smoothed segments?

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [December 12, 2023, 9:36pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/18 "2023-12-12T21:36:03Z")

</div>

> [@mikebind](#):
>
> Is your conclusion that you were only able to achieve non-collision by accepting bad smoothing? That is, there was not a method you found which gave good smoothing results without also introducing overlaps or inappropriate gaps between smoothed segments?

It appears to be like that.  
The problem is avoiding the overlaps

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [December 12, 2023, 9:50pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/19 "2023-12-12T21:50:08Z")

</div>

I’m surprised. From my admittedly naïve perspective, I don’t see why this is an especially difficult problem. It is easily detectable from the source labelmap exactly where two segments are in contact. Couldn’t that contact surface be smoothed, and then that shared surface be connected to each of the two segments for that region of the smoothed representation (with same triangluation but reversed surface normals for each to keep the proper sense of inside vs outside)? Mentally, that’s what I always assumed “joint smoothing” was doing under the hood.

---

<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:** [December 12, 2023, 10:05pm UTC](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012/20 "2023-12-12T22:05:10Z")

</div>

> [@mikebind](#):
>
> Couldn’t that contact surface be smoothed, and then that shared surface be connected to each of the two segments for that region of the smoothed representation (with same triangluation but reversed surface normals for each to keep the proper sense of inside vs outside)? Mentally, that’s what I always assumed “joint smoothing” was doing under the hood.

This is exactly what I had understood too based on the description from Bill Lorensen back in the day that he was using [this algorithm](https://insight-journal.org/browse/publication/740) and then doing the same mesh operations to both sides of the shared interface. But I checked with Mauro’s data by exporting to labelmap and running JointSmoothing in ModelMaker and it does have the same behavior. Looking at the implementation it seems that it doesn’t use the Cuberille approach.

[Next page](https://discourse.slicer.org/t/segmented-exported-surfaces-overlap-unexpected/33012.md?page=2)
