Segmentation getBounds

Hi everyone,
I am interested in cropping images around each segmentation I have at hand. Naively, I though that the method GetBounds would provide me a bounding box around each segmentation. Here is the snippet I used to get the information.

def getbounds_segmentations(node_string=‘RTSTRUCT’):
segmentationNode = slicer.util.getNode(node_string)
segmentation = segmentationNode.GetSegmentation()
dico_seg = {}
for i in range(segmentation.GetNumberOfSegments()):
bounds = [0]*6
seg_name = segmentation.GetNthSegment(i).GetName()
current_seg = segmentation.GetNthSegment(i)
current_seg.GetBounds(bounds)
dico_seg[seg_name] = bounds
return dico_seg

here is the output dictionnary:

{‘FOIE (% Max=40) - R’: [-178.71093750000003, 88.8671875, 141.59375, 193.3515625, -677.5, -355.5], ‘FOIE (Adaptatif) - R’: [-178.71093750000003, 83.3479995727539, 142.82000732421875, 189.4453125, -675.5, -355.5], ‘FOIE (Black) - R’: [-178.71093750000003, 88.23500061035156, 142.5703125, 192.50799560546875, -675.5, -353.5], ‘FOIE (Fitting) - R’: [-178.71093750000003, 78.45999908447266, 146.4765625, 187.62100219726562, -673.5, -357.5], ‘FOIE (Nestle) - R’: [-178.71093750000003, 82.53299713134766, 145.4669952392578, 188.46875, -675.5, -355.5], ‘Structure 001-os (% Max=40) - R’: [-178.9429931640625, 88.8671875, 141.59375, 193.3515625, -677.5, -355.5], ‘Structure 001-os (Adaptatif) - R’: [-178.73899841308594, 82.03125, 143.546875, 189.4453125, -675.5, -355.5], ‘Structure 001-os (Black) - R’: [-178.9429931640625, 87.890625, 142.5703125, 192.375, -675.5, -353.5], ‘Structure 001-os (Fitting) - R’: [-178.73899841308594, 77.1484375, 146.4765625, 187.4921875, -673.5, -356.40350341796875], ‘Structure 001-os (Nestle) - R’: [-178.9429931640625, 82.03125, 145.5, 188.46875, -675.5, -355.5]}

As you can see, despite the fact that the structures are way apart, the bounding box values are quite the same. slicer1

What am I missing here ?
Best regards
Ludovic

The feature that you are considering implementing is already available in “Split volume” effect (provided by SegmentEditorExtraEffects extension).

GetBounds provides union of bounds of the all representation of the segment. This is guaranteed to contain the segment but not guaranteed to be minimum size. Computing the minimum size can be an expensive operation that you can perform whenever it is necessary. For example, for binary labelmap representation, you can use vtkSegmentationCore.vtkOrientedImageDataResample.CalculateEffectiveExtent as it is done in Crop volume effect (that Split volume effect uses internally).

Thank you Andras.
This is a nice feature. Is it possible to use it by scripting ?
One more thing, my main objective here would be to create a majority voting (or staple) labelmap for each segmentation (I have 5 segmentations for each localisation of interest, eg: 5 for liver, 5 for tumor1, etc …). One way of doing whould be to create one labelmap for each segmentation considering the whole volume (which is not really efficient). And, as the number of segmentation is really large (up to 200), I came to the idea of cropping the volume before the creation of the labelmap. Is it a correct way of handling this ? if yes, what would be the best approach ?
Best regards
Ludovic

All Slicer features are available using Python scripting. See examples in the script repository.

I’m not sure I understand the question. Please use segment and segmentation terms as defined here to make things more clear. If possible, also add a few pictures to explain what you would like to do.