and then i move the segments to segmentation module and export it as a new label map, once the new label map is created and the segments are exported to the new LabelMap node, on the main screen i selected the new label map and it was preserving the segment colors.
But once i save the label map to my destination folder and reload it again with the scan, the colors are not preserved. (its changing to color code 1 and color code 2)
I want to preserve the colors that have been used at the segment editor in the saved Nifti label map. i need the output folder to have a Nifti LabelMap as i will be using python to read Nifti files and extract segmented regions based on the color codes in the LabelMap.
The point is you do have to create a custom color table, if you want the indices to reflect your values.
Saved that genericColor table, somewhere on the disk, and edit with text editor to change the indices (the leftmost value in the rows) to match your indices. Save it. Load into your scene, and export your segmentation one more time to a labelmap by specifying the in the Segmentation module
Here is an example one that exports my labels with indices 35, 42, 74, 500 and 502
there is already a color node called âGenericColorsâ which is available as one of the standard options in 3D slicer. i was just using this color table.
However, the error occurs when I export the segment regions created using âSegment Editorâ module as a label map using the âSegmentationsâ module. when I load the saved label file again in a new scene The colors are not preserved, irrespective of any names given to a segment.
I will also give the custom color table solution a try.
You should create a custom table, if you want to use your own colors. As you can see number 1 is green, and two is yellow in GenericColors, and since you specified that it rightly exported the file with those colors and indices.
@Vishal_P here are some instructiosn with MRHead.
Create three blank segments with names, Red, Blue and Green, and assign those colors to these segments. Then proceed with generating some segmentation like this:
Go to the segmentations module, and export this as a labelmap (without specfying any color table). Notice that exported labelmap has correct colors. Then save this labelmap and reload this into Slicer, and you will see that colors are now green yellow and brown, because without knowing anything about your custom colors, slicer applied the Generic Color table.
During the export, Segmentations actually exported your custom color table as well. So go to the volumes module and change the assigned color table from the Lookup table and scroll down to find your table (which in my case is a called Segmentation-label_ColorTable). When you switch to this, you should see your original colors.
Now, if you also want to change the indices from 1, 2, 3 to some custom numeric index, you should save this color table to disk, open it and edit the index values and then reload, and re-export using this color table (e.g., in the screenshot below, the indices in the labelmap is now 100, 200, 300, and colors are the original colors).
The point is, labelmap representation does know not anything about the colors it needs to be assigned. You need to specify that yourself.
Thanks for the explanation. Now, I understand what is happening. Is there any way that, when reloading the label file in the âAdd Data into the Sceneâ screen and clicking on âShow Options,â it automatically detects the intended color map (in your example, âSegmentation-label_ColorTableâ)?"
and i also noticed if the segments are directly saved without exporting to label map, in â.seg.nrrdâ the colors are preserved.
You should always save your segmentation in the seg.nrrd format for archival purposes, particularly if you care for data fidelity. labelmap doesnât have those features hence is only supported as a âExportâ format.
It will be probably be more convenient if you simply have your custom color map added to the Slicer defaults, and you can choose the correct color map from the volume lookup table. I imagine it is also possible to automate this through some customization script.