How to change segmentID of existing segmentations

Hi all,

How can I change the segmentIDs/tags of existing segmentations? Currently, saving a colour table results in these default values (in bold) but I would like to set my own tags for the existing segmentations that I have.

0 Background 0 0 0 0
1 Muscle 255 0 0 255
2 SAT 0 255 255 255
3 VAT 255 255 0 255
4 Bone 0 0 255 255


What do you mean by tag? Labelmap voxel value? Segment name? In user interface or using Python scripting?

Note that a segmentation can contain overlapping segments and multiple segments can use the same label value (e.g., if you imported them from multiple labelmaps). The overly simplistic approach that many other software does (that can only represent a segmentation as a 3D labelmap volume) may not be directly transferable but we should be able to achieve what you need.

Can you describe your overall goal? What is the clinical problem you are trying to solve and what is your current plan to achieve that?

Hi Andras,

Sorry - yes, i meant Labelmap voxel value.

My overall goal is to segment muscle, fat and bone in whole-body CT scans. My lab has already pre-defined the Labelmap voxel values for each segment component to keep things consistent. I would like to change the current Labelmap voxel values to the ones set by my lab both for existing segmentations and for future segmentations.

It would be great to know how to change that in both the UI and through Python scripting.


1 Like

Please let me know if there is a solution to achieve this!


If you start from an empty segmentation template then you can set the label values once and those are preserved (if you don’t delete the segment or copy the segment into another segmentation that already uses that label value).

@Sunderlandkyl Do we a helper function in segmentation MRML or logic classes to change associated label value in a segment? (if we keep getting these requests then we may need to expose label and layer value assignment on the GUI and add a flag to allow locking of label&layer for a segment).

There aren’t any helper functions for changing label values or layers currently.

1 Like

I’ve added a features request for allowing customization of label values: Probably we’ll get to it within a few months.

Until then you can use the template approach and/or export segmentation to a labelmap volume node and change label values as needed like this:

labelmapVolumeName = 'Segmentation-label'
originalLabelValue = 1
newLabelValue = 5

labelmapVolumeNode = slicer.uitil.getNode(labelmapVolumeName)
labelmapArray = slicer.util.arrayFromVolume(labelmapVolumeNode)
labelmapArray[ labelmapArray==originalLabelValue ] = newLabelValue
labelmapArray = slicer.util.arrayFromVolumeModified(labelmapVolumeNode)