# Edit Segmentation Locally

**URL:** <https://discourse.slicer.org/t/edit-segmentation-locally/35154>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [March 28, 2024, 3:09pm UTC](https://discourse.slicer.org/t/edit-segmentation-locally/35154 "2024-03-28T15:09:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaraabdelazim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/yaraabdelazim/32/69460_2.png) [@yaraabdelazim](https://discourse.slicer.org/u/yaraabdelazim)\
**Post date:** [March 28, 2024, 3:09pm UTC](https://discourse.slicer.org/t/edit-segmentation-locally/35154/1 "2024-03-28T15:09:21Z")

</div>

Hello,  
I have recently developped a module that segments an MRI based on edge/contour detection. However, some of the time, those contours aren’t “perfect”. For instance, sometimes they’re not closed. Other times, they’re too small or too large so I’m looking for a way to be able to edit them locally. For example, I would like to develop a tool that would allow me to drag the contour to stretch it or compress it. Or maybe a tool where I would mark a point in the image and the contour would go to it. However, I don’t really know where to begin to develop such a tool. I’ve tried looking into markup points but I don’t see how I can use them in this case. Does anyone have any ideas on how to proceed from here?

Thank you in advance.

---

<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:** [March 28, 2024, 4:15pm UTC](https://discourse.slicer.org/t/edit-segmentation-locally/35154/2 "2024-03-28T16:15:55Z")

</div>

You can use markup curves.

> [@yaraabdelazim](#):
>
> I have recently developped a module that segments an MRI based on edge/contour detection

Note that neural networks such as nn-UNet and MONAI Auto3DSeg are so successful in image segmentation tasks that they make most previous approaches completely irrelevant. Instead of trying to fix some imperfect contours, I would recommend to consider using neural networks for segmentation.

What do you segment on what kind of images? We may be able to point to pre-trained models that can do the task already.

---

<div class="post-metadata">

**Author:** ![yaraabdelazim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/yaraabdelazim/32/69460_2.png) [@yaraabdelazim](https://discourse.slicer.org/u/yaraabdelazim)\
**Post date:** [March 28, 2024, 4:20pm UTC](https://discourse.slicer.org/t/edit-segmentation-locally/35154/3 "2024-03-28T16:20:54Z")

</div>

> [@lassoan](#):
>
> You can use markup curves.

How would I use markup curves to edit the segmentation?

> [@lassoan](#):
>
> What do you segment on what kind of images? We may be able to point to pre-trained models that can do the task already.

I am working with MRI images of the hepatobiliary system and I am segmenting the bile ducts. Here’s an example on one of the slices:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/d/8dd073bd0549db52fe6631f3caa3f6dd2b19b138.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:** [March 28, 2024, 4:45pm UTC](https://discourse.slicer.org/t/edit-segmentation-locally/35154/4 "2024-03-28T16:45:53Z")

</div>

I haven’t tried any models for bile duct segmentation, but there are lots of models out there. You can simply google for `bile duct segmentation model` maybe also add `github` to find those that are openly available. They are most likely work significantly better than any contour based methods.

If you want to edit segmented bile ducts (provided by either AI models or some classic approaches), you can post-process the images a bit (e.g., Smoothing effect in Segment Editor) and then use VMTK extension to reconstruct a centerline.
