Remove multiple labels in 1 bone and have only 1 label per bone

Hello! I have a multilabel skeleton mask for MRI images of the skeleton. But for the same bone I sometimes get different labels, like in the image attached where the first bone gets a red label and a green label. But in fact I need one label for each bone. Is there any way or sitk function to fix this?
I am working with sitk and itk-snap. Thanks in advance!

Using 3D Slicer’s segment editor’s logical operators it should be easy to merge green label into the red one.

Using ITK-SNAP there is a workaround: select red as the active label, for “paint over” choose the green label. Then paintbrush, enable 3D, set the radius to maximum, then paint over the green label.

Thank you for your fast reply!
Apart from this solution, is there any sitk function or solution I could use in python?

Automating this probably isn’t trivial.

Hello @Vilma_Bozgo,

Assuming the labels you want to combine form a single connected component, then the solution is trivial (ConnectedComponentImageFilter), see code below. Also, based on the image you provided you do not want to simply replace existing label values as there are “green” labeled pixels on both the upper and lower vertebra and those need to be mapped differently.

import SimpleITK as sitk

# Label image with three labels, mimicking the setup above 
label_image = sitk.Image([128,128], sitk.sitkUInt8)
label_image[40:50, 40:50] = 50
label_image[50:60, 40:50] = 100
label_image[40:50, 80:90] = 200
label_image[50:60, 80:90] = 100
sitk.Show(label_image, 'original labels')

#relabel using connected components
relabeled_image = sitk.ConnectedComponent(label_image)
sitk.Show(relabeled_image, 'new labels')
3 Likes

Okey, thank you!