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

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.

    # Keep the selected island
    effect = segmentEditorWidget.activeEffect()
    print 'Island effect name', effect
    #operationName = 'KEEP_LARGEST_ISLAND'
    operationName = 'KEEP_SELECTED_ISLAND'
    minSize = 1000
    effect.setParameter("MinimumSize", minSize);

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.

Department of Nuclear Medicine
Christian Medical College,

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

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

1 Like

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 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()
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.ThresholdBetween(pixelValue, pixelValue)

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


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).

1 Like

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

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?

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

Thanks, I’ll update.