Change Display Lookup Table from Grey to Some Other Colour by Default

Hi There,

I need to use a specific colour map to view data meaning that whenever I open 3d Slicer I have to first go and change the Lookup Table from the default Grey to a colour table I’ve added called NDT. This isn’t a problem but adds some amount of time each time I load a new volume. For my purposes I will use this NDT colourmap 99% of the time and so it would be great to simply have it be the colourmap in the Lookup Table by default (like Grey is now).

Any chance this is possible?

Many Thanks,

  • Jon

You can change the default volume display node to use any color node you like:

displayNode = slicer.mrmlScene.CreateNodeByClass('vtkMRMLScalarVolumeDisplayNode')
displayNode.UnRegister(None)
displayNode.SetAndObserveColorNodeID('vtkMRMLColorTableNodeRainbow')
slicer.mrmlScene.AddDefaultNode(displayNode)

If you want to use this setting in all your Slicer sessions, then add these lines to your application startup script.

Hi Andras,

Thank you for your quick response! After adding the code snippet above to my .slicerrc.py file, Slicer crashes when I load data. If it makes a difference I am loading .nrrd files.

Any further guidance would be greatly appreciated!

  • Jon

Do you have any problems if you load a sample data set (e.g., MRHead)?

What Slicer version do you use, on what operating system?

Do you see any errors in the application log? (menu: Help / Report a bug -> select the log file of the previous session)

Hi Andras,

When I load MRHead slicer doesn’t crash but the colour stays Grey.

I am currently using 4.10.1 on Windows 10.

When I try to load my own data again the log after crash gives the following:

[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - Session start time …: 2020-12-10 13:04:13
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - Slicer version …: 4.10.1 (revision 27931) win-amd64 - installed release
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - Operating system …: Windows / Professional / (Build 9200) - 64-bit
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - Memory …: 16205 MB physical, 42113 MB virtual
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - CPU …: GenuineIntel , 4 cores, 4 logical processors
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - VTK configuration …: OpenGL2 rendering, TBB threading
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - Developer mode enabled …: no
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - Prefer executable CLI …: yes
[DEBUG][Qt] 10.12.2020 13:04:13 (unknown:0) - Additional module paths …: (none)
[DEBUG][Python] 10.12.2020 13:04:15 [Python] (C:\Program Files\Slicer 4.10.1\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: Annotations
[DEBUG][Python] 10.12.2020 13:04:16 [Python] (C:\Program Files\Slicer 4.10.1\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentEditor
[DEBUG][Python] 10.12.2020 13:04:16 [Python] (C:\Program Files\Slicer 4.10.1\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentStatistics
[DEBUG][Qt] 10.12.2020 13:04:16 (unknown:0) - Switch to module: “Welcome”
[INFO][Stream] 10.12.2020 13:04:16 (unknown:0) - Loading Slicer RC file [C:/Users/jlesage/.slicerrc.py]
[DEBUG][Qt] 10.12.2020 13:04:16 (unknown:0) - Switch to module: “Reformat”

Hi Again,

I realise that the crash was related to the scene and annotation files in the directory I loaded, which happens for some reason when I save scenes sometimes.

When I remove these files and just load the nrrd file, slicer doesn’t crash, rather the volume is loaded in Grey as was the case with the MRHead nrrd file.

I think maybe I am missing something in else in the .slicerrc script?

  • Jon

Slicer-4.10 is very old. This feature was not available then. You always need to use at the latest Slicer Stable Release.

Hi Again Andras,

I’ve downloaded the latest stable release as you’ve suggested. This bit of code does not take effect. Even if I simply enter it in the PYTHON terminal in slicer itself the colour remains Grey.

Any ideas?

The code changes the default display node. It does not affect nodes that are already loaded into the scene. Try loading MRHead after you running the code snippet.

If you load data from DICOM then the display node may be created explicitly (bypassing the default node mechanism), I’ll have a look at this if it can be changed easily. In the meantime, you can take a slightly different approach and add an observer to the NodeAdded event of the scene and if a scalar volume display node is added then change the color node in it. Probably you can copy-paste the code from examples in the script repository.

I see that the colormap is overridden when you simply use “Add data” window. So, until default color node usage gets used consistently with all loading modes, you need to implement the the scene observation mechanism. You can start from this example and just modify a few lines (change the existing display node instead of creating a volume rendering display node).

I’ve fixed the issue in Slicer core: now color node specified in the default vtkMRMLScalarVolumeDisplayNode always takes precedence over hardcoded values specified in the color logic or volume node class. So, the 3-line code snippet will work in Slicer Preview Release that you download tomorrow or later.

Andras,

Many Thanks!!

1 Like