# Unable to pass island selection coordinate to Islands effect by python script

**URL:** <https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747>\
**Category:** Development\
**Created:** [August 12, 2018, 9:53pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747 "2018-08-12T21:53:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![devakumar](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@devakumar](https://discourse.slicer.org/u/devakumar)\
**Post date:** [August 12, 2018, 9:53pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/1 "2018-08-12T21:53:25Z")

</div>

Dear Development team, I appreciate your work on the segment editor effects.

I am trying to select an island from the selected segmentation by python script. I am using the following code.

```auto
    # Keep the selected island
    segmentEditorWidget.setActiveEffectByName("Islands")
    effect = segmentEditorWidget.activeEffect()
    print 'Island effect name', effect
    #operationName = 'KEEP_LARGEST_ISLAND'
    operationName = 'KEEP_SELECTED_ISLAND'
    minSize = 1000
    effect.setParameter("Operation",operationName)
    effect.setParameter("MinimumSize", minSize);
    effect.self().onApply()

```

I don’t know how to set the parameter to pass the coordinate for island selection. Could you please help me. `KEEP_LARGEST_ISLAND` operation works fine as it doesn’t require a coordinate to be passed.

Regards  
Devakumar  
Department of Nuclear Medicine  
Christian Medical College,  
Vellore-632004  
India

---

<div class="post-metadata">

**Author:** ![Andinet\_Enquobahrie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andinet_enquobahrie/32/75_2.png) [@Andinet\_Enquobahrie](https://discourse.slicer.org/u/Andinet_Enquobahrie)\
**Post date:** [August 13, 2018, 12:13pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/2 "2018-08-13T12:13:09Z")

</div>

Take a look at it the processInteractionEvents method in the Islands Effect python script.

> <https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Segmentations/EditorEffects/Python/SegmentEditorIslandsEffect.py#L210-L317>

I am not sure if there is easy easy way to do this. You will need to do a bit more coding to get this working (get the pixel position of the selected island, instantiate a flood fill filter based on the pixel value of the selected island, and update the islands effect default modifier labelmap using the flood fill filter results)

Hope this helps  
-Andinet

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [April 5, 2019, 10:25pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/3 "2019-04-05T22:25:51Z")

</div>

I want to do something very similar to this. I would like to use another segment’s binary label map as seed points for selecting islands to keep. I am prepared to extract and modify the relevant parts of the code [Andinet\_Enquobahrie](https://discourse.slicer.org/u/Andinet_Enquobahrie) linked above, but I have not been able to figure out how to get a list of IJK points from a binary label map.

Specifically, I know if I have a vtkSegment called seg in python, I can get its label map via `labelMap = seg.GetRepresentation('Binary labelmap').`

And I see that I can find a select a segment from seed points using a flood filter like this:  
`floodFillingFilter = vtk.vtkImageThresholdConnectivity()`  
`floodFillingFilter.SetInputData(inputLabelImage)`  
`seedPoints = vtk.vtkPoints()`  
`origin = inputLabelImage.GetOrigin()`  
`spacing = inputLabelImage.GetSpacing()`  
`seedPoints.InsertNextPoint(origin[0]+ijk[0]*spacing[0], origin[1]+ijk[1]*spacing[1], origin[2]+ijk[2]*spacing[2])`  
`floodFillingFilter.SetSeedPoints(seedPoints)`  
`floodFillingFilter.ThresholdBetween(pixelValue, pixelValue)`

But I don’t know how to get IJK seed points from the labelmap. Any suggestions?

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:** [April 6, 2019, 12:51pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/4 "2019-04-06T12:51:33Z")

</div>

You can use `numpy.where` function to get a list of ijk indices, then convert them to RAS, and from there convert to ijk indices of segmentation’s internal labelmap.

However, if the goal is to keep only islands that intersect with other segments then Grow from seeds effect should do a much better job. Use the segment that you want to process as _mask segment_ (set “Editable area: Segment …” and then hide that segment to not use it as seed) and the other (one or more) segments will be used as seeds (if they overlap with a region in the mas segment then that region in the mask segment will retained in the output).

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [April 6, 2019, 5:03pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/5 "2019-04-06T17:03:11Z")

</div>

Thanks Andras, I’ll try that approach instead. Much appreciated!

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [April 15, 2019, 4:12pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/6 "2019-04-15T16:12:59Z")

</div>

I appreciate the suggestion, but the “Grow from seeds” effect says that it ignores masking settings, and indeed, when I tried this approach the resulting segment spilled outside the masking segment. Do you have another suggestion?

---

<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 15, 2019, 4:48pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/7 "2019-04-15T16:48:54Z")

</div>

In recent Slicer versions, a Grow from seeds effect takes masking settings into account.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [April 15, 2019, 4:55pm UTC](https://discourse.slicer.org/t/unable-to-pass-island-selection-coordinate-to-islands-effect-by-python-script/3747/8 "2019-04-15T16:55:18Z")

</div>

Thanks, I’ll update.
