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)
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() floodFillingFilter.SetInputData(inputLabelImage) seedPoints = vtk.vtkPoints() origin = inputLabelImage.GetOrigin() spacing = inputLabelImage.GetSpacing() seedPoints.InsertNextPoint(origin+ijk*spacing, origin+ijk*spacing, origin+ijk*spacing) floodFillingFilter.SetSeedPoints(seedPoints) 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).
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?