I am using slicer.util.loadColorTable('c:/Users…) in slicerrc.py to direct Slicer to load a custom color table file in a specified location. This works great, however, when I close the scene and “Add Data into the scene”, the option for my custom colour table no longer shows up in the drop-down menu. How can I prevent the table from disappearing after closing a scene?
There is no standard way of storing label and color information in a volume file.
One option is to save the scene (containing the labelmap and color table) as a single .mrb file. Click on the package icon in the Save data dialog to toggle between single/multi-file saving.
Or, you can save the segmentation as a segmentation node (right-click the labelmap volume node to convert it to segmentation). Segmentation files are volume files that contain all segment names and color in custom fields.
invertedocean = slicer.vtkMRMLColorTableNode()
invertedocean.SetTypeToUser()
invertedocean.SetNumberOfColors(256)
invertedocean.SetName("InvertedOcean")
for i in range(0,255):
invertedocean.SetColor(i, 0.0, 1 - (i+1e-16)/255.0, 1.0, 1.0)
slicer.mrmlScene.AddNode(invertedocean)
It also gives the option to choose the InvertedOcean color but disappears after closing a scene. Can the script be modified so that the color is saved?
There are many options to keep a node around but probably the simplest is to make it a singleton node (one instance per scene, identified by node type and singleton tag, not deleted when scene is closed) by calling invertedocean.SetSingletonTag("Vincent.InvertedOcean").
This sounds like a possible solution! Say I am using the command: slicer.util.loadColorTable(‘c:/Users/Vince/My_Color_Table.ctbl’) - Can I also use the singleton tag to keep the node corresponding vtkMRMLColorTableNode around?