MultiLabelSTAPLEImageFilter does not work

Dear all,
I’m trying to use MultiLabelSTAPLEImageFilter to combine several segmentations.
However, when I run the code, nothing happens. The code seems to be running for hours, and calling ctrl + C to stop it does not do anything. Is MultiLabelSTAPLE supposed to take that long? Are my files too big? (they are images of size 105 x 100 x 120)
I’ve also tried LabelVoting, which works perfectly.

Here is my code:

segmentations = [sitk.ReadImage(file_name, sitk.sitkUInt8, imageIO=“NiftiImageIO”)
for file_name in path_to_segmentations]
filter = sitk.MultiLabelSTAPLEImageFilter()
filter.SetLabelForUndecidedPixels(255)
reference_segmentation_STAPLE = filter.Execute(segmentations)
sitk.WriteImage(reference_segmentation_STAPLE)

Thanks in advance!

Hello @Fleur,

No, this shouldn’t go on for ever, please see the artificial example below. As you are using the default filter settings, it would make sense to try and set appropriate values for the terminationUpdateThreshold and maximumNumberOfIterations.

import SimpleITK as sitk

# Artificial two label segmentation
image_size = [105,100,120]
box_size = [20,30,40]
box_start_indexes = [[10,10,10], [60,60,60]]
original = sitk.Image(image_size, sitk.sitkUInt8)
for i, si, in enumerate(box_start_indexes,1):
    original[si[0]:si[0]+box_size[0],
             si[1]:si[1]+box_size[1],
             si[2]:si[2]+box_size[2]] = i

sitk.WriteImage(original, 'original.mha')

# Variations on the original using distance maps to do dilations
thresh = [4, 8, 16]
distance_maps = [sitk.SignedMaurerDistanceMap(original==i, squaredDistance=False, useImageSpacing=True) for i in range(1,len(box_start_indexes)+1)]

segmentations = []
for t in thresh:
    seg = sitk.Image(image_size, sitk.sitkUInt8)
    for i, dm in enumerate(distance_maps,1):
        seg += (dm<t)*i
    segmentations.append(seg)
    sitk.WriteImage(seg, str(t)+'.mha')

labelForUndecidedPixels = 255
reference_STAPLE = sitk.MultiLabelSTAPLE(segmentations,
                                         labelForUndecidedPixels)
sitk.WriteImage(reference_STAPLE,'reference_STAPLE.mha')
1 Like

Thank you for your help !
The example works perfectly, I will try setting the parameters you suggested.

1 Like