How to prevent Slicer from "forgetting" slicer.util.loadColorTable after closing a scene

Hi all,

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?

Thanks

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.

Hi Andras,

Thanks for the reply. What if I were to use a script similar to that from https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Create_custom_color_table in slicerrc.py?:

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?

Thanks

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").

Hi Andras,

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?

Thanks

Yes, you can make any node singleton by setting its SingletonTag.

Oh that is great! I am a novice user, can you give me an example of how to do that if my node is as so: image

slicer.util.load... methods return the loaded node, so you can call SetSingletonTag on that.

1 Like