# How to fill small holes in segmentations

**URL:** <https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701>\
**Category:** Support\
**Tags:** segmentation, dicom\
**Created:** [August 9, 2022, 10:37pm UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701 "2022-08-09T22:37:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomdillon97](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@tomdillon97](https://discourse.slicer.org/u/tomdillon97)\
**Post date:** [August 9, 2022, 10:37pm UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/1 "2022-08-09T22:37:06Z")

</div>

Hi,

I’m having trouble filling the small voids in this model. I’ve tried using the “closing” operation as visualized in the photo, though it seems to have no effect. Does anyone know of alternative tools I could use here?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/e/1e34e3c602f6b02fe4ef805845ea3252ed11ae87.jpeg)

Thanks so much  
Tom

---

<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:** [August 9, 2022, 10:38pm UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/2 "2022-08-09T22:38:46Z")

</div>

Smoothing effect’s “closing” operation should work well, just make sure to reset masking settings (allow editing everywhere by turning off editable intensity range, etc.).

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [August 10, 2022, 1:57am UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/3 "2022-08-10T01:57:41Z")

</div>

you can try margin effect , [shrink] and [grow]

---

<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:** [August 10, 2022, 9:44am UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/4 "2022-08-10T09:44:52Z")

</div>

It’s true that morphological closing is closely related to shrinking and growing, but their order matters.

Closing: dilation (growing) followed by erosion (shrinking) - it fills holes. Opening: erosion followed by shrinking - it removes small extrusions.

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [August 10, 2022, 11:42am UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/5 "2022-08-10T11:42:05Z")

</div>

you are right lasso  
if only for exhibition,can use margin effect  
it’s not appropriate for caculation

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [August 10, 2022, 11:51am UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/6 "2022-08-10T11:51:01Z")

</div>

Try with greater kernel size… 12 … 18…

It will be a lengthy processing; you could save time using the sphere brush in slice views or 3D views. It should be doable.

---

<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:** [August 11, 2022, 8:46pm UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/7 "2022-08-11T20:46:58Z")

</div>

You’ve raised a very good point. If you want to use a very large kernel (20-30 pixels) then Smoothing effect’s Closing operation will be very slow. However, if you perform Margin effect’s grow operation and then shrink operation as @jay1987 suggested then you’ll get the same output as from a closing operation; but it will be hundreds of times faster (because margin effect uses a distance map instead of a kernel to dilate and erode).

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [August 12, 2022, 8:36am UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/8 "2022-08-12T08:36:56Z")

</div>

The speed benefit of Margin’s Grow/Shrink is indeed confirmed.

However, the final result is less precise, please compare the second and third images below :

 ![holes_0](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/f/7f448b47488525df304a6603c852578f33dd3d03.png)

 ![holes_grow_shrink](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/0/a02a2d3cfd0867eda47b7480c81b73a3ef506868.png)

 ![holes_smoothing](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/e/8e5d6e1a58f1ddcc27fff7071a0cd55826a8aabb.png)

---

<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:** [August 13, 2022, 8:57pm UTC](https://discourse.slicer.org/t/how-to-fill-small-holes-in-segmentations/24701/9 "2022-08-13T20:57:59Z")

</div>

The result should be about the same (maybe the boundary may differ by 1-2 voxels). Note that margin size (it is a radius) is half of the closing kernel size (it is a diameter).
