Niels
(nLs)
July 13, 2020, 11:40am
1
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 );
lassoan
(Andras Lasso)
July 14, 2020, 6:33am
2
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
Niels
(nLs)
July 14, 2020, 7:50pm
3
Thanks lassoan!
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
Niels
(nLs)
July 15, 2020, 4:18pm
4
found a useful example here:
import os
import unittest
import vtk, qt, ctk, slicer
import logging
from slicer.ScriptedLoadableModule import *
from slicer.util import TESTING_DATA_URL
import vtkSegmentationCore
class SegmentationsModuleTest1(unittest.TestCase):
def setUp(self):
""" Do whatever is needed to reset the state - typically a scene clear will be enough.
"""
slicer.mrmlScene.Clear(0)
def runTest(self):
"""Run as few or as many tests as needed here.
"""
self.setUp()
This file has been truncated. show original