# Watershed, Fast marching, and Flood filling effects in Segment editor

**URL:** <https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104>\
**Category:** Support\
**Tags:** feature\
**Created:** [April 13, 2017, 2:06pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104 "2017-04-13T14:06:28Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [April 13, 2017, 2:06pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/1 "2017-04-13T14:06:28Z")

</div>

Three semi-automatic segmentation effects have added to the Segment editor. They are available in the latest nightly build, by installing the new SegmentEditorExtraEffects extension:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/c/bcd7e45bcb3ec95798c05e4aac7191ff76f21174.png)

They are all semi-automatic methods, which grow segmentation from seeds/points defined by the user.

**Watershed:** similar to grow from seeds. Advantage: smoothness of the segments can be enforced. Disadvantage: much slower.

Input:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/a/9a871f85e08685c5fafc0c5a30364eb601f8fc92.png)

Preview:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/9/d9029072f77f5a988008adb42a859442728aab7b.png)

Final result:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/a/9ab28d335fc3cba9efb3b44f951d2097e8edafdf.png)

**Fast marching:** expands the current segment to regions with similar intensity.  
Input:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/4/e4dfba5f73866f0b34f9ae67fda654f805afa92e.png)  
Output:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/d/0d56d5eed8efff2304fce059a2a27dc014b6db82.png)

**Flood filling:** clicking in the image adds points around the click position to the current segment. Intensity tolerance is adjustable. Neighborhood size parameter can be used to prevent leakage.

![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/9/79a696c16e778ab397483d7c1acd3576a98d4687.png)

---

<div class="post-metadata">

**Author:** ![agirault](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/agirault/32/74_2.png) [@agirault](https://discourse.slicer.org/u/agirault)\
**Post date:** [April 13, 2017, 7:21pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/2 "2017-04-13T19:21:40Z")

</div>

That’s exciting, thank you @lassoan! Looking forward to testing those.

---

<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 2, 2017, 1:05pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/3 "2017-08-02T13:05:06Z")

</div>

2 posts were split to a new topic: [Flood filling segment editor effect does not fill the image](https://discourse.slicer.org/t/flood-filling-segment-editor-effect-does-not-fill-the-image/806)

---

<div class="post-metadata">

**Author:** ![monstercolorfun\_co](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@monstercolorfun\_co](https://discourse.slicer.org/u/monstercolorfun_co)\
**Post date:** [November 29, 2017, 9:44pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/4 "2017-11-29T21:44:13Z")

</div>

Hi, Perhaps I have some contributions to boost the processing times very much.

I researched about flood-fill recently and implemented an algorythm that was 10^1000000 times more efficient on memory instructions, using 3-4 of them, and multiple times faster than all previous versions that I found described on the web in codes whilst also being able to add codes from them too, and that could be speeded up by the 3D processes of the ones I found on the web. I wrote an account here: [http://unity3dmc.blogspot.fr/2017/02/ultimate-3d-floodfill-scanline.html](http://unity3dmc.blogspot.fr/2017/02/ultimate-3d-floodfill-scanline.html)

---

<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 30, 2017, 4:39am UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/5 "2017-11-30T04:39:04Z")

</div>

@monstercolorfun_co Thanks for sharing this.

For us, the main challenge is not computation time, as typically medical images that we work with consists of 100-200 million voxels, but a segmented structure is rarely bigger than a few 10 million voxels. Flood filling time is not noticeable.

Our problem is leaking: we often want to prevent flood filling to propagate through narrow bridges. [VTK’s flood fill filter](https://www.vtk.org/doc/nightly/html/classvtkImageThresholdConnectivity.html) has an option for defining neighborhood size and minimum fill rate, but it’s not perfect, as it also removes small details from the filled region. Maybe it could be fixed easily (e.g., by expanding the final flood fill result by neighborhood size), but maybe a completely different approach would be needed.

If you were interested in exploring flood filling algorithms that don’t leak, and contribute an implementation using BSD-type license, then we would be happy to try it.

---

<div class="post-metadata">

**Author:** ![Justin\_Cramer](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@Justin\_Cramer](https://discourse.slicer.org/u/Justin_Cramer)\
**Post date:** [June 1, 2018, 4:48pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/6 "2018-06-01T16:48:38Z")

</div>

I’d love to use these new tools but I can’t get the extension to work. I installed the SegmentEditorExtraEffects extension in the 4/9/2018 nightly build, did the restart, and the icons aren’t available. I uninstalled and reinstalled also, and gave it permission to install the MarkupsToModel dependency. Working in Windows 10. Thanks for any advice.

---

<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:** [June 1, 2018, 5:34pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/7 "2018-06-01T17:34:01Z")

</div>

Use the latest stable or the latest nightly. If you still have problems then send the application log (menu: Help / Report a bug).

---

<div class="post-metadata">

**Author:** ![Justin\_Cramer](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@Justin\_Cramer](https://discourse.slicer.org/u/Justin_Cramer)\
**Post date:** [June 1, 2018, 7:01pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/8 "2018-06-01T19:01:13Z")

</div>

I’m using the build from 5/20. Here’s my error logs:

## After install, before restart:

“Retrieving extension metadata [extensionId: 225963]”  
“Downloading extension [itemId: 360938]”  
“Retrieving extension metadata [extensionId: 225914]”  
“Downloading extension [itemId: 360889]”  
“Installed extension SegmentEditorExtraEffects (225963) revision b6cdcaa”  
“Installed extension MarkupsToModel (225914) revision a63c166”  
QPixmap::scaled: Pixmap is a null pixmap

## After restart:

Session start time …: 2018-06-01 14:56:08  
Slicer version …: 4.9.0-2018-05-20 (revision 27197) win-amd64 - installed release  
Operating system …: Windows / Professional / (Build 9200) - 64-bit  
Memory …: 16309 MB physical, 19253 MB virtual  
CPU …: GenuineIntel , 4 cores, 4 logical processors  
VTK configuration …: OpenGL2 rendering, TBB threading  
Developer mode enabled …: no  
Prefer executable CLI …: yes  
Additional module paths …: C:/Users/Justin Cramer/AppData/Roaming/NA-MIC/Extensions-27197/SegmentEditorExtraEffects/lib/Slicer-4.9/qt-scripted-modules, C:/Users/Justin Cramer/AppData/Roaming/NA-MIC/Extensions-27197/MarkupsToModel/lib/Slicer-4.9/qt-loadable-modules  
Popen(%s, cwd=%s, universal\_newlines=%s, shell=%s)  
Popen(%s, cwd=%s, universal\_newlines=%s, shell=%s)  
libpng warning: iCCP: known incorrect sRGB profile  
Scripted subject hierarchy plugin registered: Annotations  
Scripted subject hierarchy plugin registered: SegmentEditor  
Scripted subject hierarchy plugin registered: SegmentStatistics  
Switch to module: “SegmentEditor”  
An OpenGL Core Profile was requested, but it is not supported on the current platform. Falling back to a non-Core profile. Note that this might cause rendering issues.  
QPixmap::scaled: Pixmap is a null pixmap

---

<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:** [June 2, 2018, 12:06am UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/9 "2018-06-02T00:06:55Z")

</div>

This version is not the latest nightly or latest stable version. Could you please test with both of these versions and let us know if they work?

---

<div class="post-metadata">

**Author:** ![Justin\_Cramer](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@Justin\_Cramer](https://discourse.slicer.org/u/Justin_Cramer)\
**Post date:** [June 2, 2018, 11:12pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/10 "2018-06-02T23:12:00Z")

</div>

Ok, I tried it on latest stable (4.8.1) and nightly build from 6/1 with same result. I’ve pasted log from 4.8.1 attempt below. Have tried on 3 different Windows 10 machines with no difference. I don’t have access to OSX or Linux right now. Thanks again for your help.

```auto
[DEBUG][Qt] 02.06.2018 18:08:55 [] (unknown:0) - Session start time .......: 2018-06-02 18:08:55
[DEBUG][Qt] 02.06.2018 18:08:55 [] (unknown:0) - Slicer version ...........: 4.8.1 (revision 26813) win-amd64 - installed
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - Operating system .........: Windows / Professional / (Build 9200) - 64-bit
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - Memory ...................: 16322 MB physical, 19266 MB virtual
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - CPU ......................: GenuineIntel , 12 cores, 16 logical processors
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - Developer mode enabled ...: no
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - Prefer executable CLI ....: yes
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - Additional module paths ..: C:/Users/neurorad/AppData/Roaming/NA-MIC/Extensions-26813/SegmentEditorExtraEffects/lib/Slicer-4.8/qt-scripted-modules, C:/Users/neurorad/AppData/Roaming/NA-MIC/Extensions-26813/MarkupsToModel/lib/Slicer-4.8/qt-loadable-modules
[DEBUG][Python] 02.06.2018 18:08:56 [Python] (C:\Program Files\Slicer 4.8.1\lib\Python\Lib\site-packages\git\cmd.py:719) - Popen(%s, cwd=%s, universal_newlines=%s, shell=%s)
[DEBUG][Python] 02.06.2018 18:08:56 [Python] (C:\Program Files\Slicer 4.8.1\lib\Python\Lib\site-packages\git\cmd.py:719) - Popen(%s, cwd=%s, universal_newlines=%s, shell=%s)
[DEBUG][Python] 02.06.2018 18:08:57 [Python] (C:\Program Files\Slicer 4.8.1\lib\Slicer-4.8\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: Annotations
[DEBUG][Python] 02.06.2018 18:08:57 [Python] (C:\Program Files\Slicer 4.8.1\lib\Slicer-4.8\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentEditor
[DEBUG][Python] 02.06.2018 18:08:57 [Python] (C:\Program Files\Slicer 4.8.1\lib\Slicer-4.8\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentStatistics
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - Number of registered modules: 141
[DEBUG][Qt] 02.06.2018 18:08:56 [] (unknown:0) - Number of instantiated modules: 141
[DEBUG][Qt] 02.06.2018 18:08:57 [] (unknown:0) - Number of loaded modules: 141
[DEBUG][Qt] 02.06.2018 18:08:57 [] (unknown:0) - Switch to module: "SegmentEditor"

```

---

<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:** [June 3, 2018, 12:52am UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/11 "2018-06-03T00:52:58Z")

</div>

I’ve just tried the nightly build on a Windows machine and the effects showed up correctly. Could you please post a screenshot of your screen when you switch to the Segment Editor module?

---

<div class="post-metadata">

**Author:** ![Justin\_Cramer](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@Justin\_Cramer](https://discourse.slicer.org/u/Justin_Cramer)\
**Post date:** [June 3, 2018, 5:59pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/12 "2018-06-03T17:59:46Z")

</div>

Yeah I’m sure it’s something simple I’m overlooking but can’t figure it out. I rebooted…latest updates installed to Windows 10, otherwise fresh install of Slicer. It’s my impression that the extra tools show up as additional icons in the Segement Editor… Here are screenshots of Segment Editor and my Extensions manager:

 ![extensions](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/5/b52419372f90b2c233cacba5b526e0211fa16550.png) ![segment_editor](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/3/d3d5af0113fee953776d5fc6b1b163f126682f15.jpeg)

---

<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:** [June 3, 2018, 6:44pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/13 "2018-06-03T18:44:39Z")

</div>

Yes, the extra icons should show up in the Segment Editor module, but they don’t. Could you try to uninstall the extension, restart Slicer, and reinstall. When you reinstall, wait 1 minute before restarting Slicer, to make sure the extension is fully downloaded and installed.

If it still does not work then we can set up a meeting with remote desktop sharing during the coming week (just Send me a few timeslots that would work for you in a private message).

---

<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:** [June 4, 2018, 5:43pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/14 "2018-06-04T17:43:37Z")

</div>

Mystery solved: SegmentEditor module was set as startup module, so it was initialized immediately when Slicer started - before SegmentEditorExtraEffects extensions had a chance to register the additional effects.

I’ll push a fix for this soon, but until then the workaround is not to set SegmentEditor as startup module.

---

<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:** [June 5, 2018, 2:18pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/15 "2018-06-05T14:18:45Z")

</div>

Segment Editor initialization has been fixed (r27233), in nightly versions downloaded tomorrow or later, all effects will show up correctly in Segment Editor, even if it is used as startup module.

---

<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:** [June 5, 2018, 2:29pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/16 "2018-06-05T14:29:55Z")

</div>

Yaay for using Segment Editor as startup module 🙂

---

<div class="post-metadata">

**Author:** ![AndyM](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@AndyM](https://discourse.slicer.org/u/AndyM)\
**Post date:** [February 18, 2019, 2:27pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/17 "2019-02-18T14:27:53Z")

</div>

Hi these effects are so nice , and gives best output.  
i like to use python coding.  
Can i call/use this effects from Slicer python interactor?

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 22, 2019, 1:38pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/18 "2019-02-22T13:38:19Z")

</div>

Yes I’m also interested to use this by python code.

---

<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:** [February 22, 2019, 2:37pm UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/19 "2019-02-22T14:37:34Z")

</div>

> [@AndyM](#):
>
> Can i call/use this effects from Slicer python interactor?

All Slicer features are available from Python scripting. See examples for using Segment Editor effects from Python in the script repository: [Documentation/Nightly/ScriptRepository - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script)

---

<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:** [February 4, 2022, 4:25am UTC](https://discourse.slicer.org/t/watershed-fast-marching-and-flood-filling-effects-in-segment-editor/104/21 "2022-02-04T04:25:06Z")

</div>

A post was split to a new topic: [Algorithm used in Watershed effect in Segment Editor](https://discourse.slicer.org/t/algorithm-used-in-watershed-effect-in-segment-editor/21796)
