massachusetts general hospital python scripting in …

40
MASSACHUSETTS GENERAL HOSPITAL RADIATION ONCOLOGY Python Scripting in 3D Slicer Greg Sharp @ MGH July 19, 2019

Upload: others

Post on 14-Nov-2021

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

MASSACHUSETTSGENERAL HOSPITAL

RADIATION ONCOLOGYPython Scripting in 3D Slicer

Greg Sharp @ MGHJuly 19, 2019

Page 2: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Disclosures

No conflict of interest

Page 3: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Disclaimer

“The Software has been designed for research purposes only and has not been reviewed or

approved by the Food and Drug Administration or by any other agency”

Page 4: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Development in Slicer

● Slicer modules– Command line module

– Scripted module

– Loadable module

● Matlab bridge

Page 5: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Python scripting

● Python only● Very easy and powerful

– You can make a GUI

– Or just run commands

● Included: numpy, VTK, CTK, PythonQt, SimpleITK

Page 6: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 7: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 8: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 9: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

MRML Nodes

MRMLNode

StorageNode

MRMLScene

Image,Markups,

Segments,Etc.

Attributes

DisplayNode

Page 10: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 11: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 12: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

MRML Nodes

MRMLNode

StorageNode

MRMLScene

Image,Markups,

Segments,Etc.

Attributes

DisplayNode

Page 13: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 14: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 15: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 16: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 17: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Node references

● Nodes can refer to other nodes using

the concept of a node reference

MRMLNode

MRMLNode

Page 18: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Node reference

# Create model nodemodel = slicer.vtkMRMLModelNode()

# Create model nodetransform = slicer.vtkMRMLLinearTransformNode()

# Transform model by reference to transform node model.SetAndObserveTransformNodeID(

transform.GetID())

LinearTransform

3DModel

Page 19: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Node attributes

Page 20: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

SimpleITK

● An easy way to use ITK functions in python● But, requires extra step to move images between SimpleITK

and Slicer

Page 21: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 22: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 23: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 24: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Python modulesclass ExampleModule(ScriptedLoadableModule): def __init__(self, parent): ScriptedLoadableModule.__init__(self, parent) self.parent.title = "Hello Python" self.parent.categories = ["Examples"] self.parent.dependencies = [] self.parent.contributors = ["Jean-Christophe ..."] self.parent.helpText = ...

class ExampleModuleWidget(ScriptedLoadableModuleWidget): def __init__(self, parent = None): ScriptedLoadableModuleWidget.__init__(self, parent) self.logic = ExampleModuleLogic()

def setup(self): ScriptedLoadableModuleWidget.setup(self) inputCollapsibleButton = ctk.ctkCollapsibleButton() inputCollapsibleButton.text = "A Collapsible Button" self.layout.addWidget(inputCollapsibleButton)

Commonmodule attributes

Module UI

Page 25: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Python modules

Commonmodule attributes

Module UI

Page 26: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Calling Slicer modules

● Slicer modules can be called from python● CLI modules follow this pattern:

– Create any needed output nodes

– Set parameters

– Call CLI function

Page 27: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 28: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 29: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 30: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 31: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 32: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 33: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 34: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 35: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Python scripting

● As of June 2019, python binary packages can be used

Page 36: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 37: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 38: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Python script repository

More than 100 simple examples

Page 39: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …
Page 40: MASSACHUSETTS GENERAL HOSPITAL Python Scripting in …

Links

● https://www.slicer.org/● https://www.slicer.org/wiki/Documentation/Nightly/Training● https://www.slicer.org/wiki/Documentation/Nightly/Developers● https://discourse.slicer.org/