Skip to content

Segmentation Automation Ideas

KKnoernschild edited this page Mar 8, 2019 · 1 revision

slicer.util.loadLavelVolume(filename) -> loads into scene

current test

Cant properly call slicer --python-script , so Im just testing using built in python with slicer currently

Load in color Table

slicer.util.loadColorTable('/home/kknoernschild/Documents/BrainLabelMapandNrrd/BAWHDAdultAtlas_FreeSurferConventionColorLUT_20160524_ModifiedForSlicer.txt')

Load in Label volume

slicer.util.loadLabelVolume('/home/kknoernschild/Documents/BrainLabelMapandNrrd/TRIO_TRIO_MR2_dense_seg.nii.gz')

Find Volume Node

singlenode = slicer.util.getNode("TRIO_TRIO_MR2_dense_seg")

Find Display Node ( this is where you can apply the labelmap)

displaynode = singlenode.GetDisplayNodeID() you can get the colornodeID , which is the lookuptable, by calling displaynode.GetColorNodeID()

Change lookuptable

displaynode.SetAndObserveColorNodeID("vtkMRMLColorTableNode1")

Node1 refers to the lookuptable being loaded in as the 1st non vtk standard node.

standard Lookuptable:

standardlookuptable

Custom lookuptable:

CustomLookupTableApplied

After applying the custom lookup table, both the label strings and their pixel colors change accordingly.

From this point, I should be able to create a segmentation node, and apply the lookuptable to the node, creating a segmentation image

Testing Script

tried using the regular module , but I think the python script has to be located in the same spot as the Slicer.exe . Downloaded the nightly build, and put my script for creating the segmentation of the human brain, and it runs properly.

testpycall

Run-time for creating segmentation is 17.954 seconds.

Naming conventions:

In order to call the script, I have to call the Slicer.exe within the module path, so the command call is currently:

/nfsscratch/opt/iiai/Slicer3D/4.10.1/Slicer --no-main-window --python-script /home/kknoernschild/Documents/BrainLabelMapandNrrd/testpythonscriptoutputs/TestScript.py

--no-main-window just prevents slicer opening the visual portion

FINAL STEPS:: ARGPARSE IMPLEMENTATION - only need to introduce an argparse that will pass 2 string s to the program. Input Labelmap, and Input LUT

Clone this wiki locally