Difference between revisions of "Documentation/4.3/ScriptRepository"

From Slicer Wiki
Jump to: navigation, search
(Moved FillRoi.py module to an official extension: VolumeClip (Volume clip with ROI))
 
(4 intermediate revisions by one other user not shown)
Line 6: Line 6:
  
 
Usage: save the .py file to a directory, add the directory to the additional module paths in the Slicer application settings.
 
Usage: save the .py file to a directory, add the directory to the additional module paths in the Slicer application settings.
 
==Segmentation==
 
* [https://subversion.assembla.com/svn/slicerrt/trunk/SlicerRt/sandbox/FillRoiModule/FillRoi.py FillRoi.py]: Fill a region of interest in a labelmap volume with a constant value. This can be used after an automatic segmentation for removing certain regions of a volume.
 
  
 
==Filters==
 
==Filters==
Line 31: Line 28:
 
   img = qt.QPixmap.grabWidget(slicer.app.layoutManager().sliceWidget(viewNames[0]))
 
   img = qt.QPixmap.grabWidget(slicer.app.layoutManager().sliceWidget(viewNames[0]))
 
* [https://subversion.assembla.com/svn/slicerrt/trunk/SlicerRt/sandbox/CaptureRotationVideo/CaptureRotationVideo.py CaptureRotationVideo.py]: Capture a video of the scene rotating in the 3D view
 
* [https://subversion.assembla.com/svn/slicerrt/trunk/SlicerRt/sandbox/CaptureRotationVideo/CaptureRotationVideo.py CaptureRotationVideo.py]: Capture a video of the scene rotating in the 3D view
 +
* To create an animated gif of the saved frames, you can use the following tools:
 +
** [https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sips.1.html sips] (Mac only) to convert single frame to GIF format (cannot save as .gif with QImage)
 +
** [http://www.lcdf.org/gifsicle/ gifsicle] to combine individual frames into a single animated gif (gifsicle is a command line tool, so you can batch it!)
 +
 
==Launching Slicer==
 
==Launching Slicer==
 
* How to open an .mrb file with Slicer at the command line?
 
* How to open an .mrb file with Slicer at the command line?
Line 36: Line 37:
 
* How to run a script in the Slicer environment in batch mode (without showing any graphical user interface)?
 
* How to run a script in the Slicer environment in batch mode (without showing any graphical user interface)?
 
   Slicer.exe --python-code "doSomething; doSomethingElse; etc." --testing --no-splash --no-main-window
 
   Slicer.exe --python-code "doSomething; doSomethingElse; etc." --testing --no-splash --no-main-window
* To create an animated gifs of the saved frames, you can use the following tools:
 
** [[https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sips.1.html sips] (Mac only) to convert single frame to GIF format (cannot save as .gif with QImage)
 
** [[http://www.lcdf.org/gifsicle/ gifsicle]] to combine individual frames into a single animated gif (gifsicle is a command line tool, so you can batch it!)
 

Latest revision as of 19:05, 25 October 2014

Home < Documentation < 4.3 < ScriptRepository


For the latest Slicer documentation, visit the read-the-docs.



Community-contributed modules

Usage: save the .py file to a directory, add the directory to the additional module paths in the Slicer application settings.

Filters

DICOM

Community-contributed examples

Usage: Copy-paste the shown code lines or linked .py file contents into Python console in Slicer.

Capture

  • Get a MRML node in the scene based on the node name and call methods of that object. For the MRHead sample data:
 vol=slicer.util.getNode('MR*')
 vol.GetImageData().GetDimensions()
  • Capture the full Slicer screen and save it into a file
 img = qt.QPixmap.grabWidget(slicer.util.mainWindow()).toImage()
 img.save('c:/tmp/test.png')
    • To capture the content of a slice viewer:
 viewNames = slicer.app.layoutManager().sliceViewNames()
 img = qt.QPixmap.grabWidget(slicer.app.layoutManager().sliceWidget(viewNames[0]))
  • CaptureRotationVideo.py: Capture a video of the scene rotating in the 3D view
  • To create an animated gif of the saved frames, you can use the following tools:
    • sips (Mac only) to convert single frame to GIF format (cannot save as .gif with QImage)
    • gifsicle to combine individual frames into a single animated gif (gifsicle is a command line tool, so you can batch it!)

Launching Slicer

  • How to open an .mrb file with Slicer at the command line?
 Slicer.exe --python-code "slicer.util.loadScene( 'f:/2013-08-23-Scene.mrb' )"
  • How to run a script in the Slicer environment in batch mode (without showing any graphical user interface)?
 Slicer.exe --python-code "doSomething; doSomethingElse; etc." --testing --no-splash --no-main-window