Difference between revisions of "Slicer3:Slicer Daemon"

From NAMIC Wiki
Jump to: navigation, search
Line 35: Line 35:
 
A [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Python/ Python based] set of code for interacting with the Slicer Daemon is provided.
 
A [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Python/ Python based] set of code for interacting with the Slicer Daemon is provided.
  
For example, the following code reads a volume and creates a new volume where each voxel is the square of the corresponding voxel of the input image.  The new image is then sent back to slicer.
+
For example, the [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Python/mathExample.py?view=log following code] reads a volume and creates a new volume where each voxel is the square of the corresponding voxel of the input image.  The new image is then sent back to slicer.
  
 
<pre>
 
<pre>
Line 49: Line 49:
  
 
s.put(n, 'newImage')
 
s.put(n, 'newImage')
 +
</pre>
 +
 +
For example, the [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Python/sliceExample.py?view=log following code] reads a volume and extracts a slice of it for plotting using the matplotlib code (see [http://www.scipy.org the SciPy website] for more info on Python numerics and plotting).
 +
 +
<pre>
 +
import slicerd
 +
import pylab
 +
 +
s = slicerd.slicerd()
 +
 +
n = s.get(0)
 +
 +
slice = n.getImage()[16,:,:]
 +
pylab.imshow(slice)
 +
pylab.show()
 
</pre>
 
</pre>
  
 
== Matlab ==
 
== Matlab ==

Revision as of 14:35, 19 March 2007

Home < Slicer3:Slicer Daemon

Goals and Functionality

The Slicer Daemon refers to a network protocol that can be used to connect to a running instance of slicer to read and write data in the MRML scene and execute other commands. The name is based on the unix system convention of naming network services 'daemons'.

Server Implementation

The file slicerd.tcl implements the server side functionality.

By default it listens for connections on port 18943.

Clients

Tcl

Two utilities are provided:

  • slicerget.tcl is used to read volumes out of slicer. The volume is written to the stdout of the slicerget command in nrrd format.
  • slicerput.tcl is used to write volumes into slicer. The volume is read in nrrd format from stdin of slicerput and loaded into the mrml scene.

Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):

# a noop -- just copy image onto itself
slicerget.tcl 1 | slicerput.tcl noop
# put external data into slicer
unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl
# run an external command and put the data back into slicer
slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs

Python

A Python based set of code for interacting with the Slicer Daemon is provided.

For example, the following code reads a volume and creates a new volume where each voxel is the square of the corresponding voxel of the input image. The new image is then sent back to slicer.

import slicerd
import numpy

s = slicerd.slicerd()

n = s.get(0)

im = n.getImage()
n.setImage( im * im )

s.put(n, 'newImage')

For example, the following code reads a volume and extracts a slice of it for plotting using the matplotlib code (see the SciPy website for more info on Python numerics and plotting).

import slicerd
import pylab

s = slicerd.slicerd()

n = s.get(0)

slice = n.getImage()[16,:,:]
pylab.imshow(slice)
pylab.show()

Matlab