# Need to segment a hole

**URL:** <https://discourse.slicer.org/t/need-to-segment-a-hole/19445>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [August 31, 2021, 6:12pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445 "2021-08-31T18:12:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordanan](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jordanan](https://discourse.slicer.org/u/jordanan)\
**Post date:** [August 31, 2021, 6:12pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/1 "2021-08-31T18:12:04Z")

</div>

I would like to segment a hole in a bone. Having no luck with thresholding is there another way that can allow me to do this quickly?

Thanks

---

<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 31, 2021, 6:14pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/2 "2021-08-31T18:14:08Z")

</div>

It should be no problem to segment a hole using Segment Editor. If the hole is filled with fluid or soft tissue then contrast compared to the bone should be quite high, so thresholding should work well. You can attach an image to show us what kind of image you work with and why segmentation is challenging.

---

<div class="post-metadata">

**Author:** ![jordanan](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jordanan](https://discourse.slicer.org/u/jordanan)\
**Post date:** [September 3, 2021, 3:17pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/3 "2021-09-03T15:17:33Z")

</div>

![IMG_6187 2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/7/77811fa873ace25c89362e00f159a5d8c2da4640.jpeg)

Thresholding is difficult because it is a similar color to bone.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 3, 2021, 4:35pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/4 "2021-09-03T16:35:41Z")

</div>

If the hole you want to segment is little circle in the red slice view, that should be no problem. There is a nice bright edge that should let you define a threshold that will pickup everything inside the hole, but not the edge. And then you can just use that as a masking value and point over the slices.

---

<div class="post-metadata">

**Author:** ![jordanan](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jordanan](https://discourse.slicer.org/u/jordanan)\
**Post date:** [September 3, 2021, 5:43pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/5 "2021-09-03T17:43:48Z")

</div>

Okay, can you explain further. When I try to just threshold that small circle it gets parts of the bone as well.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 3, 2021, 5:58pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/6 "2021-09-03T17:58:09Z")

</div>

When you are in the threshold tool, you need to reduce the right hand side of the slide so that it is picking on the contents of the hole, but not the bone. The left hand side will be either at 0.

The click the use for masking, and then use the paint tool (with 3D option) to start painting inside the hole.

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

---

<div class="post-metadata">

**Author:** ![jordanan](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jordanan](https://discourse.slicer.org/u/jordanan)\
**Post date:** [September 7, 2021, 1:47pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/7 "2021-09-07T13:47:10Z")

</div>

Is their any way to do this more automatic using thresholding.

Is their a way to utilize the bright edge around the hole

---

<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 7, 2021, 1:53pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/8 "2021-09-07T13:53:38Z")

</div>

Yes, you can fully automate everything using Python scripting. You can find many examples in the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#how-to-run-segment-editor-effects-from-a-script).

However, probably you can segment a hole with semi-automatic tools in about 1 minute (after you have learned how to use the segment editor module), so you would only benefit of automation if you had to segment over a thousand or so data sets.

I would recommend to try the Local threshold effect. You can segment the hole with it by a couple of clicks:

[![](https://img.youtube.com/vi/cevlMLyhfK8/maxresdefault.jpg "Segment Editor: New "Local threshold" effect") ](https://www.youtube.com/watch?v=cevlMLyhfK8)

---

<div class="post-metadata">

**Author:** ![jordanan](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jordanan](https://discourse.slicer.org/u/jordanan)\
**Post date:** [September 9, 2021, 2:26pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/9 "2021-09-09T14:26:01Z")

</div>

Thank you Local thresholding seems to work well.

In the top hole it is also segmenting outside the knee bone though. Is their a way to solve this, do I have to use the ROI?

---

<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 9, 2021, 4:48pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/10 "2021-09-09T16:48:09Z")

</div>

There are many ways to prevent leaking at the imaged region boundary (for example, you could crop the volume before segmentation; or define a free-form masking region), but defining a ROI for the local thresholding is probably the easiest to do.

---

<div class="post-metadata">

**Author:** ![jordanan](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jordanan](https://discourse.slicer.org/u/jordanan)\
**Post date:** [September 9, 2021, 5:33pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/11 "2021-09-09T17:33:52Z")

</div>

Okay good to hear. How do I define a masking region?

Also I tried to use the ROI but having trouble. From my understanding I have to have a local threshold segment, then create a new segment, press local threshold, create new ROI, an dc put it in my desired region. But how do I actually get it to create the segmentation, what button do I press?

---

<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 9, 2021, 6:19pm UTC](https://discourse.slicer.org/t/need-to-segment-a-hole/19445/12 "2021-09-09T18:19:06Z")

</div>

> [@jordanan](#):
>
> Okay good to hear. How do I define a masking region?

You can create a segment using any tools and then choose to [use it as editable area](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmenteditor.html#panels-and-their-use). However, as I wrote above, using a ROI should be simpler.

> [@jordanan](#):
>
> Also I tried to use the ROI but having trouble.

Define a ROI using the toolbar (choose to place ROI, drop two points, and adjust the ROI bounds as needed), then activate the Local threshold effect, define the intensity range (for example, by drawing a small region with a similar intensity range in one of the slice views), and then Ctrl+Click in a slice view to add that region to the segment.
