I have a label map with numbers which I would like to keep when I convert it to a segment but I don’t know if this is possible.
For example i have labels 1,3,5,8 but I think I loose them to segment 0 1 2 and 4.
I have looked-up this function but I don’t know if this is what I need or how it works?
/// Update segmentation from segments in a labelmap node.
/// \param updatedSegmentIDs Defines how label values 1…N are mapped to segment IDs (0…N-1).
static bool ImportLabelmapToSegmentationNode(vtkOrientedImageData* labelmapImage,
vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* updatedSegmentIDs,
vtkGeneralTransform* labelmapToSegmentationTransform=nullptr );
Probably the easiest is to create a color table (.ctbl) file that contains your segment names. The format is a simple text file that you can create in any text editor:
0 background 0 0 0 0
1 first 128 174 128 255
2 second 241 214 145 255
3 and_the_last_one 177 122 101 255
You can use this color table like this:
- Load this color table into Slicer
- Load the labelmap volume into Slicer, in Add data dialog check “Show options” and check “LabelMap” checkbox and select your custom color table
- Convert the loaded labelmap volume to segmentation volume by right-clicking on it in Data module
But i still need to understand the ImportLabelmapToSegmentationNode function to get the right ids after import.
If found an alternative way by iterating the Label_1 to Label_N segments and i would like to change their id to somthing else but there is only a function to change a segment name. Not the id.
Do you know how this function works or how i change the ids?
I am working with python
found a useful example here: