# Extract sub-segment from segmentation based on seed and volume (in Python)

**URL:** <https://discourse.slicer.org/t/extract-sub-segment-from-segmentation-based-on-seed-and-volume-in-python/20196>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [October 17, 2021, 8:30pm UTC](https://discourse.slicer.org/t/extract-sub-segment-from-segmentation-based-on-seed-and-volume-in-python/20196 "2021-10-17T20:30:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkkkkkk123](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kkkkkkk123](https://discourse.slicer.org/u/kkkkkkk123)\
**Post date:** [October 17, 2021, 8:30pm UTC](https://discourse.slicer.org/t/extract-sub-segment-from-segmentation-based-on-seed-and-volume-in-python/20196/1 "2021-10-17T20:30:20Z")

</div>

Hi everyone,

I’m currently having a segmented image, but now I want to create a new (sub-)segmentation from the segmented image based on an initial seed point (x,y,z) and with a given volume threshold, e.g. max 20 cc. I want to implement it in Python.  
Has anyone ever done this or any idea what the easiest way is to do this?  
Thanks in advance!

Kylie

---

<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:** [October 17, 2021, 8:40pm UTC](https://discourse.slicer.org/t/extract-sub-segment-from-segmentation-based-on-seed-and-volume-in-python/20196/2 "2021-10-17T20:40:21Z")

</div>

This is exactly what Fast Marching segment editor effect does. It is provided by SegmentEditorExtraEffects extension.

I don’t think that this is effect can take into account masking during the region growing operation. But you can blank out the volume (set it to a very different intensity) outside the mask before applying Fast Marching.

---

<div class="post-metadata">

**Author:** ![kkkkkkk123](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kkkkkkk123](https://discourse.slicer.org/u/kkkkkkk123)\
**Post date:** [October 18, 2021, 6:21am UTC](https://discourse.slicer.org/t/extract-sub-segment-from-segmentation-based-on-seed-and-volume-in-python/20196/3 "2021-10-18T06:21:56Z")

</div>

Thank you for the fast reply! I’ll look into it 😄

---

<div class="post-metadata">

**Author:** ![kkkkkkk123](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kkkkkkk123](https://discourse.slicer.org/u/kkkkkkk123)\
**Post date:** [October 19, 2021, 8:57am UTC](https://discourse.slicer.org/t/extract-sub-segment-from-segmentation-based-on-seed-and-volume-in-python/20196/4 "2021-10-19T08:57:04Z")

</div>

So I’m currently still struggling with it. The situation is that I already have a segmentation result, so I should set the output data of the vtkPichonFastMarching() either with setOutData() or SetOutput(), right? And add the seed point with either addSeed() or addSeedIJK()? So I can then perform the fm.show() operation with the given fraction? Or is there still additional information that I need to provide for the vtkPichonFastMarching?

Thanks 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:** [October 20, 2021, 5:46am UTC](https://discourse.slicer.org/t/extract-sub-segment-from-segmentation-based-on-seed-and-volume-in-python/20196/5 "2021-10-20T05:46:07Z")

</div>

I would recommend to first just use the GUI. Once you confirmed that everything works as expected you can start Python scripting to automate everything.
