<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.na-mic.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kquintus</id>
	<title>NAMIC Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.na-mic.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kquintus"/>
	<link rel="alternate" type="text/html" href="https://www.na-mic.org/wiki/Special:Contributions/Kquintus"/>
	<updated>2026-04-29T22:36:43Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22028</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22028"/>
		<updated>2008-02-08T22:58:36Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Slicer-Matlab interface and tensor data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
=== Core Utilities ===&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
=== Example use of the SlicerDaemon to manipulate the MRML Scene ===&lt;br /&gt;
&lt;br /&gt;
The following example can be run from any tcl interpreter to interact with a running slicer instance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# the next line restarts using tclsh \&lt;br /&gt;
exec tclsh &amp;quot;$0&amp;quot; &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# tracker.tcl&lt;br /&gt;
# - communicates with slicerd&lt;br /&gt;
# - edits the value of a transform to do a little animation&lt;br /&gt;
# - illustration of how a tracking device can inject coordinates to slicer&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# first, get a non-blocking socket connection to slicer&lt;br /&gt;
set ::sock [socket localhost 18943]&lt;br /&gt;
fconfigure $::sock -buffering none&lt;br /&gt;
&lt;br /&gt;
# this helper routine evaluates a command in slicer's interpreter&lt;br /&gt;
proc slicer {cmd} {&lt;br /&gt;
  puts $::sock &amp;quot;eval $cmd&amp;quot;&lt;br /&gt;
  flush $::sock&lt;br /&gt;
  gets $::sock line&lt;br /&gt;
  return $line&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# run a little sample&lt;br /&gt;
# - bring up dialog to announce the connection&lt;br /&gt;
# - find the pre-defined transform node named &amp;quot;tracker&amp;quot;&lt;br /&gt;
# - animate the probe location by setting the value of the matrix&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
slicer {tk_messageBox -message \&amp;quot;Tracker Connected\&amp;quot; -title \&amp;quot;Slicer Daemon\&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
set numTransforms [slicer {$::slicer3::MRMLScene GetNumberOfNodesByClass vtkMRMLLinearTransformNode}]&lt;br /&gt;
set myTransform [expr $numTransforms - 1]&lt;br /&gt;
set nodes [slicer [list {$::slicer3::MRMLScene GetNodesByName} &amp;quot;tracker&amp;quot;]]&lt;br /&gt;
set transformNode [slicer [list $nodes GetItemAsObject 0]]&lt;br /&gt;
set matrix [slicer [list $transformNode GetMatrixTransformToParent]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for {set loop 0} {$loop &amp;lt; 20} {incr loop} {&lt;br /&gt;
  set sign [expr pow(-1,$loop)]&lt;br /&gt;
  for {set x 0} {$x &amp;lt; 100} {incr x 10} {&lt;br /&gt;
    slicer [list $matrix SetElement 0 3 [expr $sign * $x]]&lt;br /&gt;
    after 10&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space).&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
Such transformations incur numerical errors. After both transformations the data is back in original gradient space and should be exactly the same as the data originally loaded, but this is not quite the case. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea how big this numerical error can be, the following initial test can be performed with the original file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a neccessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;br /&gt;
&lt;br /&gt;
==== TODO ====&lt;br /&gt;
&lt;br /&gt;
* the scripts need some adjustments for sending labelmaps back to Slicer (the labelmap flag needs to be set for the volume).&lt;br /&gt;
* Sending tensor data back to Slicer crashes Slicer. This has worked before but something in Slicer has changed. One idea is that a display node needs to be created now when creating the volume in Slicer.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22026</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22026"/>
		<updated>2008-02-08T20:17:17Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Slicer-Matlab interface and tensor data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
=== Core Utilities ===&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
=== Example use of the SlicerDaemon to manipulate the MRML Scene ===&lt;br /&gt;
&lt;br /&gt;
The following example can be run from any tcl interpreter to interact with a running slicer instance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# the next line restarts using tclsh \&lt;br /&gt;
exec tclsh &amp;quot;$0&amp;quot; &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# tracker.tcl&lt;br /&gt;
# - communicates with slicerd&lt;br /&gt;
# - edits the value of a transform to do a little animation&lt;br /&gt;
# - illustration of how a tracking device can inject coordinates to slicer&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# first, get a non-blocking socket connection to slicer&lt;br /&gt;
set ::sock [socket localhost 18943]&lt;br /&gt;
fconfigure $::sock -buffering none&lt;br /&gt;
&lt;br /&gt;
# this helper routine evaluates a command in slicer's interpreter&lt;br /&gt;
proc slicer {cmd} {&lt;br /&gt;
  puts $::sock &amp;quot;eval $cmd&amp;quot;&lt;br /&gt;
  flush $::sock&lt;br /&gt;
  gets $::sock line&lt;br /&gt;
  return $line&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# run a little sample&lt;br /&gt;
# - bring up dialog to announce the connection&lt;br /&gt;
# - find the pre-defined transform node named &amp;quot;tracker&amp;quot;&lt;br /&gt;
# - animate the probe location by setting the value of the matrix&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
slicer {tk_messageBox -message \&amp;quot;Tracker Connected\&amp;quot; -title \&amp;quot;Slicer Daemon\&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
set numTransforms [slicer {$::slicer3::MRMLScene GetNumberOfNodesByClass vtkMRMLLinearTransformNode}]&lt;br /&gt;
set myTransform [expr $numTransforms - 1]&lt;br /&gt;
set nodes [slicer [list {$::slicer3::MRMLScene GetNodesByName} &amp;quot;tracker&amp;quot;]]&lt;br /&gt;
set transformNode [slicer [list $nodes GetItemAsObject 0]]&lt;br /&gt;
set matrix [slicer [list $transformNode GetMatrixTransformToParent]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for {set loop 0} {$loop &amp;lt; 20} {incr loop} {&lt;br /&gt;
  set sign [expr pow(-1,$loop)]&lt;br /&gt;
  for {set x 0} {$x &amp;lt; 100} {incr x 10} {&lt;br /&gt;
    slicer [list $matrix SetElement 0 3 [expr $sign * $x]]&lt;br /&gt;
    after 10&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space).&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
Such transformations incur numerical errors. After both transformations the data is back in original gradient space and should be exactly the same as the data originally loaded, but this is not quite the case. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea how big this numerical error can be, the following inital test can be performed with the original file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;br /&gt;
&lt;br /&gt;
==== TODO ====&lt;br /&gt;
&lt;br /&gt;
* the scripts need some adjustments for sending labelmaps back to Slicer (the labelmap flag needs to be set for the volume).&lt;br /&gt;
* Sending tensor data back to Slicer crashes Slicer. This has worked before but something in Slicer has changed. One idea is that a display node needs to be created now when creating the volume in Slicer.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22025</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22025"/>
		<updated>2008-02-08T20:00:58Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Basic Slicer-Matlab tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
=== Core Utilities ===&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
=== Example use of the SlicerDaemon to manipulate the MRML Scene ===&lt;br /&gt;
&lt;br /&gt;
The following example can be run from any tcl interpreter to interact with a running slicer instance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# the next line restarts using tclsh \&lt;br /&gt;
exec tclsh &amp;quot;$0&amp;quot; &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# tracker.tcl&lt;br /&gt;
# - communicates with slicerd&lt;br /&gt;
# - edits the value of a transform to do a little animation&lt;br /&gt;
# - illustration of how a tracking device can inject coordinates to slicer&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# first, get a non-blocking socket connection to slicer&lt;br /&gt;
set ::sock [socket localhost 18943]&lt;br /&gt;
fconfigure $::sock -buffering none&lt;br /&gt;
&lt;br /&gt;
# this helper routine evaluates a command in slicer's interpreter&lt;br /&gt;
proc slicer {cmd} {&lt;br /&gt;
  puts $::sock &amp;quot;eval $cmd&amp;quot;&lt;br /&gt;
  flush $::sock&lt;br /&gt;
  gets $::sock line&lt;br /&gt;
  return $line&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# run a little sample&lt;br /&gt;
# - bring up dialog to announce the connection&lt;br /&gt;
# - find the pre-defined transform node named &amp;quot;tracker&amp;quot;&lt;br /&gt;
# - animate the probe location by setting the value of the matrix&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
slicer {tk_messageBox -message \&amp;quot;Tracker Connected\&amp;quot; -title \&amp;quot;Slicer Daemon\&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
set numTransforms [slicer {$::slicer3::MRMLScene GetNumberOfNodesByClass vtkMRMLLinearTransformNode}]&lt;br /&gt;
set myTransform [expr $numTransforms - 1]&lt;br /&gt;
set nodes [slicer [list {$::slicer3::MRMLScene GetNodesByName} &amp;quot;tracker&amp;quot;]]&lt;br /&gt;
set transformNode [slicer [list $nodes GetItemAsObject 0]]&lt;br /&gt;
set matrix [slicer [list $transformNode GetMatrixTransformToParent]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for {set loop 0} {$loop &amp;lt; 20} {incr loop} {&lt;br /&gt;
  set sign [expr pow(-1,$loop)]&lt;br /&gt;
  for {set x 0} {$x &amp;lt; 100} {incr x 10} {&lt;br /&gt;
    slicer [list $matrix SetElement 0 3 [expr $sign * $x]]&lt;br /&gt;
    after 10&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space).&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
Such transformations incur numerical errors. After both transformations the data is back in original gradient space and should be exactly the same as the data originally loaded, but this is not quite the case. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea how big this numerical error can be, the following inital test can be performed with the original file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22024</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=22024"/>
		<updated>2008-02-08T19:59:44Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
=== Core Utilities ===&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
=== Example use of the SlicerDaemon to manipulate the MRML Scene ===&lt;br /&gt;
&lt;br /&gt;
The following example can be run from any tcl interpreter to interact with a running slicer instance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# the next line restarts using tclsh \&lt;br /&gt;
exec tclsh &amp;quot;$0&amp;quot; &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# tracker.tcl&lt;br /&gt;
# - communicates with slicerd&lt;br /&gt;
# - edits the value of a transform to do a little animation&lt;br /&gt;
# - illustration of how a tracking device can inject coordinates to slicer&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# first, get a non-blocking socket connection to slicer&lt;br /&gt;
set ::sock [socket localhost 18943]&lt;br /&gt;
fconfigure $::sock -buffering none&lt;br /&gt;
&lt;br /&gt;
# this helper routine evaluates a command in slicer's interpreter&lt;br /&gt;
proc slicer {cmd} {&lt;br /&gt;
  puts $::sock &amp;quot;eval $cmd&amp;quot;&lt;br /&gt;
  flush $::sock&lt;br /&gt;
  gets $::sock line&lt;br /&gt;
  return $line&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# run a little sample&lt;br /&gt;
# - bring up dialog to announce the connection&lt;br /&gt;
# - find the pre-defined transform node named &amp;quot;tracker&amp;quot;&lt;br /&gt;
# - animate the probe location by setting the value of the matrix&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
slicer {tk_messageBox -message \&amp;quot;Tracker Connected\&amp;quot; -title \&amp;quot;Slicer Daemon\&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
set numTransforms [slicer {$::slicer3::MRMLScene GetNumberOfNodesByClass vtkMRMLLinearTransformNode}]&lt;br /&gt;
set myTransform [expr $numTransforms - 1]&lt;br /&gt;
set nodes [slicer [list {$::slicer3::MRMLScene GetNodesByName} &amp;quot;tracker&amp;quot;]]&lt;br /&gt;
set transformNode [slicer [list $nodes GetItemAsObject 0]]&lt;br /&gt;
set matrix [slicer [list $transformNode GetMatrixTransformToParent]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for {set loop 0} {$loop &amp;lt; 20} {incr loop} {&lt;br /&gt;
  set sign [expr pow(-1,$loop)]&lt;br /&gt;
  for {set x 0} {$x &amp;lt; 100} {incr x 10} {&lt;br /&gt;
    slicer [list $matrix SetElement 0 3 [expr $sign * $x]]&lt;br /&gt;
    after 10&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
Instead of stating the name of the volume in Slicer you can also state the id (first volume loaded gets assigned number &amp;quot;0&amp;quot;, ascending numbers from there): &lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space).&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
Such transformations incur numerical errors. After both transformations the data is back in original gradient space and should be exactly the same as the data originally loaded, but this is not quite the case. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea how big this numerical error can be, the following inital test can be performed with the original file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=AHM_2008&amp;diff=19826</id>
		<title>AHM 2008</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=AHM_2008&amp;diff=19826"/>
		<updated>2007-12-19T20:25:33Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Agenda */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;00&amp;quot; cellpadding=&amp;quot;8&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;| NA-MIC participants meet for a all-hands meeting (AHM) once a year. The purpose of the AHM is to coordinate, discuss plans and report to NIH officers and the external advisory board (EAB). The external advisory board meets with the NA-MIC leadership immediately after the AHM. In parallel, NA-MIC is organizing a project week. These events, with the exception of the EAB meeting, are open to collaborators and potential collaborators.&lt;br /&gt;
&lt;br /&gt;
For more information about the project weeks in general, click [[Engineering:Programming_Events|'''here''']]. &lt;br /&gt;
&lt;br /&gt;
For information about the January 2008 project week, see below or click [[2008_Winter_Project_Week|'''here''']].&lt;br /&gt;
&lt;br /&gt;
For information about Utah as a travel destination click [http://www.utah.com '''here'''].&lt;br /&gt;
| style=&amp;quot;background: #ebeced&amp;quot; colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot;| [[Image:SLC.jpg|center|350px|View of the City]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background: #ebeced&amp;quot;| &amp;lt;b&amp;gt;SLC&amp;lt;/b&amp;gt;&lt;br /&gt;
| style=&amp;quot;background: #ebeced&amp;quot;|The combined AHM, EAB and Project Week will be held in Salt Lake City, UT, January 7-11 2008. &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dates. Venue. Registration ==&lt;br /&gt;
&lt;br /&gt;
'''Dates:''' &lt;br /&gt;
* The All Hands Meeting and External Advisory Board Meeting will be held on '''Thursday, January 10th'''.  &lt;br /&gt;
* Project Activities will be held rest of the week between '''Monday, January 7th and Friday, January 11th'''.&lt;br /&gt;
&lt;br /&gt;
'''Venue:''' The venue for the meeting is [http://www.marriott.com/hotels/travel/slccc-salt-lake-city-marriott-city-center/ Marriot City Center, Salt Lake City, Utah] Mariott City Center, Salt Lake City, Utah. [http://marriott.com/property/meetingsandevents/floorplans/slccc (Floorplan)]. To reserve rooms at the meeting rate of $129/night, please either call the hotel at 1-801-961-8700 or 1-866-961-8700 (toll free) and mention that you are attending the NAMIC meeting or book online by using the code SCISCIA. Please note that we do need attendees to use this hotel in order to not incur additional charges for the use of conference rooms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt; '''Registration:''' We are charging a registration fee to all participants. The fee covers the costs of the facilities and food provided. In order to keep the fee low, we need to get a sufficient number of hotel nights by our participants. See above for more on this. Please click [http://www.sci.utah.edu/namic2008/registration.html '''here'''] for online registration. This registration must be completed by Friday, December 14, 2007. &amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Agenda ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
|- style=&amp;quot;background:#ebeced; color:black&amp;quot; align=&amp;quot;left&amp;quot; &lt;br /&gt;
| style=&amp;quot;width:4%&amp;quot; | '''Time'''&lt;br /&gt;
| style=&amp;quot;width:12%&amp;quot; | '''Monday, January 7''' &lt;br /&gt;
| style=&amp;quot;width:12%&amp;quot; | '''Tuesday, January 8'''&lt;br /&gt;
| style=&amp;quot;width:12%&amp;quot; | '''Wednesday, January 9''' &lt;br /&gt;
| style=&amp;quot;width:32%&amp;quot; | '''Thursday, January 10 '''&lt;br /&gt;
| style=&amp;quot;width:12%&amp;quot; | '''Friday, January 11''' &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:#522200&amp;quot;| '''[[2008_Winter_Project_Week|Project Activities]] '''&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:#522200&amp;quot;| '''[[2008_Winter_Project_Week|Project Activities]] '''&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:#522200&amp;quot;| '''[[2008_Winter_Project_Week|Project Activities]] '''&lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:#522200&amp;quot;| '''AHM, [[2008_EAB|EAB]]'''&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:#522200&amp;quot;| '''[[2008_Winter_Project_Week|Project Activities]] '''&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''7:30-''' &lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;|  &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Breakfast&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Breakfast&lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;| Breakfast&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Breakfast&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''8:00-10:00''' &lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;|&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work &amp;lt;br&amp;gt; [[2008 Winter Project Week Plug-ins for Slicer3|Plug-ins for Slicer3]]&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work &amp;lt;br&amp;gt;'''8:00-9:00''' [[2008 Winter Project Week IGT|IGT Breakout Session]]&amp;lt;br&amp;gt;&lt;br /&gt;
9am: [[2008 Winter Project Week Tractography|Tractography Breakout Session]] &lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;|&lt;br /&gt;
'''8:00''' Introduction, Ron Kikinis &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Core 1 and 2 Presentations'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''8:05''' Utah 1, Ross Whitaker&amp;lt;br&amp;gt;&lt;br /&gt;
'''8:20''' Utah 2, Guido Gerig&amp;lt;br&amp;gt;&lt;br /&gt;
'''8:30''': MIT, Polina Golland&amp;lt;br&amp;gt;&lt;br /&gt;
'''8:45''': Georgia Tech, Allen Tannenbaum&amp;lt;br&amp;gt;&lt;br /&gt;
'''9:00''': UNC, Martin Styner&amp;lt;br&amp;gt;&lt;br /&gt;
'''9:10''': MGH/WUSTL, Dan Marcus&amp;lt;br&amp;gt;&lt;br /&gt;
'''9:25''': Kitware, Will Schroeder&amp;lt;br&amp;gt;&lt;br /&gt;
'''9:40''': GE Research, Jim Miller&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''10:00-10:30''' &lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;| &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Coffee&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Coffee&lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;| Coffee&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Coffee&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''10:30-12:00''' &lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;|&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work &amp;lt;br&amp;gt;&lt;br /&gt;
[[2008 Winter Project Week Tractography|Tractography Breakout Session contd]]  &lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;|&lt;br /&gt;
'''10:30''': Isomics, Steve Pieper&amp;lt;br&amp;gt;&lt;br /&gt;
'''10:45''': UCSD, Mark Ellisman&amp;lt;br&amp;gt;&lt;br /&gt;
'''11:00''': UCLA, Arthur Toga&amp;lt;br&amp;gt;&lt;br /&gt;
'''11:15''': Outreach, Randy Gollub&amp;lt;br&amp;gt;&lt;br /&gt;
'''11:25''': Invited speaker: Mike Sherman, Stanford NCBC Simbios, SimTK Architect&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''12:00-1:00'''  &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Lunch&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Lunch &amp;lt;br&amp;gt; DPB Engineers: Lunch meeting&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Lunch&lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;| Lunch&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Adjourn &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''1:00-3:00''' &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Introduce Projects and Participants &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Breakout: [[2008 Winter Project Week Geometry and Topology processing of Meshes|Geometry and Topology processing of Meshes]]&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work &amp;lt;br&amp;gt; [[2008 Winter Project Week Tractography|Tractography Breakout Session contd]] &lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;|&lt;br /&gt;
'''DBP results''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''1:00''': Queens/JHU, Gabor Fichtinger&amp;lt;br&amp;gt;&lt;br /&gt;
'''1:15''':UNC, Heather Cody Hazlett&amp;lt;br&amp;gt;&lt;br /&gt;
'''1:30''':Harvard, Marek Kubicki&amp;lt;br&amp;gt;&lt;br /&gt;
'''1:45''':MIND/UNM, Jeremy Bockholt&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NCBC Collaborations'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''2:00''': Georgetown, Kevin Cleary&amp;lt;br&amp;gt;&lt;br /&gt;
'''2:15''': Wakeforest, Chris Wyatt&amp;lt;br&amp;gt;&lt;br /&gt;
'''2:30''': UIowa, Nicole Grosland,Vincent Magnotta&amp;lt;br&amp;gt;&lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''3:30-4:00''' &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Coffee&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Coffee&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;| Coffee&lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;| Coffee&lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''3:00-5:00''' &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|'''3:00-4:00''' Slicer Update &amp;lt;br&amp;gt;&lt;br /&gt;
'''4:00-5:00''' Breakout: [[2008 Winter Project Week EM Segmenter User Group|EM Segmenter User Group]]&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work &amp;lt;br&amp;gt;[[2008_Winter_Project_Week_Image_Registration_Update| Registration Breakout]]&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|Project Work &amp;lt;br&amp;gt;'''3:00-4:00''' [[2008 Winter Project Week Batchmake Update|Batchmake Update]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[2008 Winter Project Week Tractography|Tractography Breakout Session contd]] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;|[[2008 EAB|EAB]]&amp;lt;br&amp;gt;'''3:00-4:00''' Discussion with NA-MIC Leadership&amp;lt;br&amp;gt; '''4:00-5:00''' Closed Session&lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:#ffffdd; color:black&amp;quot;|'''05:00-07:00''' &lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|&lt;br /&gt;
| style=&amp;quot;background:#b4d597; color:black&amp;quot;|&lt;br /&gt;
| style=&amp;quot;background:#fff6a6; color:black&amp;quot;|'''6:00''' Optional: [http://www.skisaltlake.com/murphys.htm Beer at Murphy's] (like last year)&lt;br /&gt;
| style=&amp;quot;background:#ebeced; color:black&amp;quot;| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Please note that there will be a Core 1&amp;amp;2 Site PI Retreat starting the afternoon of Sunday, January 6 and continuing on Monday, January 7th. This is a closed session for Core 1&amp;amp;2 Site PIs, with no delegates. The topic is the competitive renewal. (It is expected that the NIH IC Directors will make decisions about the competitive renewal mechanics in mid December, at which point we will let everybody know.)&lt;br /&gt;
&lt;br /&gt;
== Attendees ==&lt;br /&gt;
&lt;br /&gt;
Please note that unlike past events, registration will not be done on the wiki. Instead you need to follow [http://www.sci.utah.edu/namic2008/registration.html this registration link] to complete your online registration.  The organizers will periodically publish the list of registered attendees in the space below.  Attendees should '''NOT''' add their names in this section.&lt;br /&gt;
&lt;br /&gt;
This is the list of attendees who have registered as of Dec 19 2007&lt;br /&gt;
&lt;br /&gt;
===AHM===&lt;br /&gt;
#	Michael J.	Ackerman, Ph.D.	National Library of Medicine	NIH Lead Science Officer&lt;br /&gt;
#	German	Cavelier	NIHNIMH	&lt;br /&gt;
#	Kevin	Cleary	Georgetown University	collaborator&lt;br /&gt;
#	Zohara	Cohen	National Institutes of Health	NIH Program Officer&lt;br /&gt;
#	Jack	Collins	SAIC-Frederick, Inc.	collaborator&lt;br /&gt;
#	Gabor	Fichtinger	Queens University	&lt;br /&gt;
#	Polina	Golland	MIT	Core 1&lt;br /&gt;
#	Randy	Gollub	MGH Department of Psychiatry	Core 5&lt;br /&gt;
#	Heather Cody 	hazlett	University of North Carolina	DBP Core2&lt;br /&gt;
#	Chris	Johnson	SCI Institute	EAB&lt;br /&gt;
#	Marek 	Kubicki	BWH	Core 3&lt;br /&gt;
#	Danial	Lashkari	MIT	Core 1&lt;br /&gt;
#	Sandy	Napel	Stanford	EAB&lt;br /&gt;
#	Godfrey	Pearlson	Yale	EAB&lt;br /&gt;
#	Fred	Prior		EAB&lt;br /&gt;
#	Yogesh	Rathi	BWH	Core 3&lt;br /&gt;
#	Mike	Sherman	Stanford	Invited Speaker&lt;br /&gt;
#	Arthur	Toga	Laboratory of Neuro Imaging, UCLA	Core 2&lt;br /&gt;
#	Chris	Wyatt	Virginia Tech	Collaborator&lt;br /&gt;
#	Terry S.	Yoo	National Library of Medicine	NIH Science Officer&lt;br /&gt;
&lt;br /&gt;
===AHM and Project Event===&lt;br /&gt;
#	Kevin	Archie	Washington University School of Medicine	&lt;br /&gt;
#	Preston Tom	Fletcher	SCI Institute	core 1&lt;br /&gt;
#	James V	Miller	GE Global Research	Core 2&lt;br /&gt;
#	Vandana	Mohan	Georgia Inst of Technology	1&lt;br /&gt;
#	Douglas	Alan	Harvard University IIC	Collaborator&lt;br /&gt;
#	Luca	Antiga	Mario Negri Institute	collaborator&lt;br /&gt;
#	Nicole	Aucoin	BWH	core 2&lt;br /&gt;
#	Stephen	Aylward	Kitware, Inc.	collaborator&lt;br /&gt;
#	serdar	balci	MIT	core 1&lt;br /&gt;
#	Sebastien	Barre	Kitware, Inc.	core 2&lt;br /&gt;
#	H Jeremy	Bockholt	The MIND Research Network	MIND DBP2&lt;br /&gt;
#	Sylvain	Bouix	Brigham and Womens Hospital	Psychiatry Neuroimaging Lab Core 3&lt;br /&gt;
#	Francois	Budin	BWH	Core 3&lt;br /&gt;
#	Patrick	Cheng	Georgetown University	collaborator&lt;br /&gt;
#	Kiyoyuki	Chinzei	AIST, Japan	collaborator&lt;br /&gt;
#	NIKOS	CHRISOCHOIDES	COLLEGE OF WILLIAM AND MARY	collaborator&lt;br /&gt;
#	Csaba 	Csoma	Johns Hopkins University	collaborator&lt;br /&gt;
#	Brad	Davis	Kitware, Inc.	Core 2&lt;br /&gt;
#	Andreas	Freudling	BWH	collaborator&lt;br /&gt;
#	Yi	Gao	Georgia Tech	Core 1&lt;br /&gt;
#	Guido	Gerig	SCI Institute	Core 1&lt;br /&gt;
#	David	Gobbi	Queens University	DBP2&lt;br /&gt;
#	Casey	Goodlett	SCI Institute	Core 1&lt;br /&gt;
#	Alexandre	Gouaillard	Caltech	collaborator&lt;br /&gt;
#	Sylvain	Gouttard	SCI Institute	core 1&lt;br /&gt;
#	Benjamin	Grauer	BWH	Leadership Core &lt;br /&gt;
#	Nicole	Grosland	The University of Iowa, CCAD	Core 3&lt;br /&gt;
#	Nathan	Hageman	UCLA	Core 2&lt;br /&gt;
#	Michael	Halle	BWH	collaborator&lt;br /&gt;
#	Kathryn	Hayes	Brigham and Womens Hospital	core 2&lt;br /&gt;
#	Bill	Hoffman	Kitware, Inc.	Core 2&lt;br /&gt;
#	Jaesung	Hong	Kyushu University	collaborator&lt;br /&gt;
#	Luis	Ibanez	Kitware, Inc.	Core 2&lt;br /&gt;
#	Julien	Jomier	Kitware, Inc.	Core 2&lt;br /&gt;
#	Ron	Kikinis	Brigham and Womens Hospital	Leadership Core&lt;br /&gt;
#	Curtis 	Lisle	KnowledgeVis, LLC	Core 2&lt;br /&gt;
#	Haiying	Liu	Brigham and Womens Hospital	collaborator&lt;br /&gt;
#	William	Lorensen		EAB&lt;br /&gt;
#	raghu	machiraju	The Ohio State University	collaborator&lt;br /&gt;
#	Vincent	Magnotta	The University of Iowa, CCAD	collaborator&lt;br /&gt;
#	Daniel	Marcus	Washington University	Core 2&lt;br /&gt;
#	Doug	Markant	BWH	core 3&lt;br /&gt;
#	Katie	Mastrogiacomo	SPL, BWH	Leadership Core&lt;br /&gt;
#	Sean	Megason	Caltech	collaborator&lt;br /&gt;
#	John	Melonakos	Georgia Tech	Core 1&lt;br /&gt;
#	Kishore	Mosaliganti	The Ohio State University	collaborator&lt;br /&gt;
#	Tri	Ngo	MIT	Core 1&lt;br /&gt;
#	Ipek	Oguz	UNC	Core 1&lt;br /&gt;
#	Steve	Pieper	Isomics, Inc.	Core 2, 6&lt;br /&gt;
#	carlo	pierpaoli	NIH	EAB&lt;br /&gt;
#	Wendy	Plesniak	BWH	collaborator&lt;br /&gt;
#	Kilian	Pohl	BWH	Core 1&lt;br /&gt;
#	Marcel 	Prastawa	SCI Institute	core 1&lt;br /&gt;
#	Sonia	Pujol	BWH	core 5&lt;br /&gt;
#	Katharina	Quintus	BWH	core 3&lt;br /&gt;
#	Mert	Sabuncu	MIT	Core 1&lt;br /&gt;
#	Raul	San Jose	BWH	collaborator&lt;br /&gt;
#	Will	Schroeder	Kitware, Inc.	Core 2&lt;br /&gt;
#	Mark	Scully	The MIND Research Network	Core 3&lt;br /&gt;
#	Kiran	Shivanna	The University of Iowa, CCAD	collaborator&lt;br /&gt;
#	Martin	Styner	UNC Chapel Hill	Core 1&lt;br /&gt;
#	Padma	Sundaram	Brigham and Womens	collaborator&lt;br /&gt;
#	Xiaodong	Tao	GE	Core 2&lt;br /&gt;
#	Kinh	Tieu	BWH	collaborator&lt;br /&gt;
#	Junichi	Tokuda	BWH	collaborator&lt;br /&gt;
#	Clement	Vachet	UNC Chapel Hill	Core 3&lt;br /&gt;
#	Koen	Van Leemput	MIT	Core 1&lt;br /&gt;
#	Carl-Fredrik	Westin	Brigham and Womens Hospital	collaborator&lt;br /&gt;
#	Nathan	Wilson	Cardiovascular Simulation, Inc.	collaborator&lt;br /&gt;
#	Alexander	Yarmarkovich	BWH 	Core 2&lt;br /&gt;
#	Boon Thye	Yeo	MIT	Core 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the list of attendees who have registered as of Dec 17 2007. Please note that unlike past events, registration will not be done on the wiki. Instead you need to follow [http://www.sci.utah.edu/namic2008/registration.html this registration link] to complete your online registration.  The organizers will periodically publish the list of registered attendees in the space above.  Attendees should '''NOT''' add their names in this section.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=2008_Winter_Project_Week&amp;diff=19808</id>
		<title>2008 Winter Project Week</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=2008_Winter_Project_Week&amp;diff=19808"/>
		<updated>2007-12-19T16:54:23Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* All Other Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Back to [[Project Events]], [[AHM_2008]], [[Events]]&lt;br /&gt;
&lt;br /&gt;
== Projects ==&lt;br /&gt;
*2008 Project Week [[2008_Winter_Project_Week_Template|'''Template''']]&lt;br /&gt;
*[[2007_Programming/Project_Week_MIT#Projects|Last Year's Projects as a reference]]&lt;br /&gt;
*For hosting projects, we are planning to make use of the NITRC resources.  See [[NA-MIC_and_NITRC | Information about NITRC Collaboration]]&lt;br /&gt;
*Next Project Week is at MIT -- June 23-27, 2008&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DBP Roadmap Projects===&lt;br /&gt;
Please note that the first four categories below correspond to four clinical Roadmap application projects that will be pursued in focused parallel tracks at the meeting, each corresponding to a DBP problem.  &lt;br /&gt;
====[[DBP2:Harvard:Brain_Segmentation_Roadmap|DBP Harvard Roadmap Project: Stochastic Tractography for Velocardio Facial Syndrome (VCFS)]]====&lt;br /&gt;
*[[2008_Winter_Project_Week:StochasticTract_Arcuate|Stochastic tractography of the arcuate fasciculus in schizophrenia]] (Marek Kubicki, Tri Ngo, Doug Markant)&lt;br /&gt;
&lt;br /&gt;
====[[DBP2:UNC:Cortical_Thickness_Roadmap|DBP UNC Roadmap Project: Cortical Thickness Measurement for Autism]]====&lt;br /&gt;
*[[2008_Winter_Project_Week:Cortical_Thickness|Cortical thickness analysis of pediatric brains]] (Heather Cody Hazlett, Martin Styner, Clement Vachet, Jim Miller)&lt;br /&gt;
&lt;br /&gt;
====[[DBP2:MIND:Roadmap|DBP MIND Roadmap Project: Brain Lesion Analysis in Neuropsychiatric Systemic Lupus Erythematosus]]====&lt;br /&gt;
*[[2008_Winter_Project_Week:Lesions|Towards an end to end lesion analysis feature in Slicer3]] (Mark Scully, Jeremy Bockholt, Brad Davis, Marcel Prastawa, Sonia Pujol, Vincent Magnotta)&lt;br /&gt;
&lt;br /&gt;
====[[DBP2:JHU:Roadmap|DBP JHU Roadmap Project: Segmentation and Registration for Robotic Prostate Intervention]]====&lt;br /&gt;
#[[2008_Winter_Project_Week:Robotic_Prostate_Interventions | Robotic Prostate Interventions]] (David Gobbi, Csaba Csoma, Junichi Tokuda, Katie Hayes)&lt;br /&gt;
#[[2008_Winter_Project_Week:Prostate_Segmentation|Prostate Segmentation]], (Yi Gao, Ponnappan Arumuganainar, John Melonakos, Allen Tannenbaum, Gabor Fichtinger)&lt;br /&gt;
&lt;br /&gt;
===All Other Projects===&lt;br /&gt;
# [[2008_Winter_Project_Week_GroupwiseReg | Groupwise Registration and Atlas Building]] (Brad Davis, Serdar Balci, Casey Goodlett)&lt;br /&gt;
# [[2008_Winter_Project_Week:MRISC|Joint Segmentation and Classification of MR Images Based on Structure-specific Affine Registration]] (Mert Sabuncu, Kilian Pohl)&lt;br /&gt;
# [[2008_Winter_Project_Week:CorPar|Cortical Surface Parcellation]] (Thomas Yeo, Mert Sabuncu)&lt;br /&gt;
# [[2008_Winter_Project_Week:Dorsolateral_Prefrontal_Cortex_Segmentation|Dorsolateral Prefrontal Cortex Segmentation]] (Marek Kubicki, Sylvain Bouix, John Melonakos, Brad Davis, Polina Golland)&lt;br /&gt;
#[[2008_Winter_Project_Week:Particle_Correspondence_DTI|Incorporating DTI data into entropy-based particle system for cortical correspondence]] (Ipek Oguz, Josh Cates, Tom Fletcher, Martin Styner)&lt;br /&gt;
#[[2008_Winter_Project_Week:Population_DTI|Integrating population based DTI tools into NAMIC Kit]] (Casey Goodlett)&lt;br /&gt;
#[[2008_Winter_Project_Week:Population_DTI_Application|Application of population based DTI tools to Schizophrenia]] (Casey Goodlett, Marek Kubicki)&lt;br /&gt;
#[[2008_Winter_Project_Week:Geodesic_Tractography_Segmentation|Geodesic Tractography Segmentation]], (John Melonakos, Allen Tannenbaum, Marek Kubicki)&lt;br /&gt;
#[[2008_Winter_Project_Week:Fluid_Mechanics_Tractography|Fluid Mechanics Based DTI Tractography]] (Nathan Hageman)&lt;br /&gt;
#[[2008_Winter_Project_Week:MRMLScenesForExecutionModel |MRML Scenes for the Execution Model including Transforms]] (Jim Miller, Brad Davis, Nicole Aucoin, Alex Yarmarkovich, Steve Pieper)&lt;br /&gt;
#Unstructured Grids and Mesh Support(Curt, Alex, Steve, Will, Vince, Bob O'Bara)&lt;br /&gt;
#[[2008_Winter_Project_Week:PythonSupport |Python Support in Slicer 3]] (Luca, Bryan Smith, Dan Blezek)&lt;br /&gt;
#[[2008_Winter_Project_Week:MRMLTransformHardening |Transform hardening in MRML]] (Luca Antiga, Steve Pieper)&lt;br /&gt;
#[[2008_Winter_Project_Week:EventBrokerInSlicer3 |Event broker in Slicer3]] (Jim, Steve, Alex Y, Luca, Dan Blezek)&lt;br /&gt;
#[[2008_Winter_Project_Week:CPack |CPack]], CTest, CMake infrastructure Improvements(Katie, Steve, Bill Hoffman, Sebastien)&lt;br /&gt;
#Drafting Human Interface and Slicer Style Guidelines (Wendy Plesniak,Sebastien Barre)&lt;br /&gt;
#Shape Descriptor Functions for Dendritic Spine Morphometrics (Bryan Smith, Padma, Martin Styner)&lt;br /&gt;
#[[2008_Winter_Project_Week_VolumeRendering|Volume rendering]] (Andy Freudling, Steve Pieper, Grauer) &lt;br /&gt;
#[[2008_Winter_Project_Week_VolumeRenderingUsingCuda|Volume rendering using Cuda]] (Andy Freudling, Steve Pieper, Grauer) &lt;br /&gt;
#[[2008_Winter_Project_Week:3DWWidgets |3D W Widgets and Picking]] (Will Schroeder, Nicole Aucoin, Curt Lisle, Kiran Shivana)&lt;br /&gt;
#[[2008_Winter_Project_Week:OutOfCoreMRML | MRML support for out of core processing with fMRI and DTI as use cases]] (Steve Pieper, Jim Miller, Wendy Plesniak, Alex Yarmakovich, Will Schroeder)&lt;br /&gt;
#[[2008_Winter_Project_Week:XNAT_Integration | XNAT Integration]] ([http://www.xnat.org XNAT], [http://www.slicer.org Slicer], [http://www.Xcede.org XCEDE], [http://www.batchmake.org Batchmake]) (Dan Marcus, Steve Pieper, Stephen Aylward, Jeff Grethe, Julien Jomier) &lt;br /&gt;
#KWWidgets Roadmap (Sebastien Barre, Wendy Plesniak, Katie Hayes)&lt;br /&gt;
#Circuit Annotation Capability (for example drawing arrows above regions that are connected functionally, structurally, etc), (Mark Scully, others)&lt;br /&gt;
#Astronomical coordinate system support (Mike Halle, Doug Alan)&lt;br /&gt;
#[[2008_Winter_Project_Week:Meshing Techniques into NA-MIC Toolkit|New Meshing Techniques into NA-MIC]] [Univ. of Iowa] (Nicole Grosland, Vince Magnotta)&lt;br /&gt;
#[[2008_Winter_Project_Week:Finite Element Meshing into NA-MIC|Meshing Workflow into Slicer]] [Univ. of Iowa] (Nicole Grosland, Vince Magnotta, Kiran Shivana, Steve Pieper, Curt Lisle, Brad Davis)&lt;br /&gt;
#[[2008_Winter_Project_Week:SmallAnimalEvalNCI |Evaluating NA-MIC Tools for Small Animal Imaging Workflows]] [NCI] (Curt Lisle, Jack Collins, Killian Pohl)&lt;br /&gt;
#[[2008_Winter_Project_Week:GoFigure |GoFigure:High-Level Microscopy Image analysis Application and Algorithms]] [CalTech-Harvard Medical School] (Alex G, Sean Megason, Arnaud Gelas?)&lt;br /&gt;
#[[2008_Winter_Project_Week:IGT_IGSTK_Slicer| IGSTK-Slicer]]  [Georgetown] (Haiying Liu, Patrick Cheng, Noby Hata, Junichi Tokuda)&lt;br /&gt;
#[[2008_Winter_Project_Week:IGT_Intelligent_Surgical_Instrument_Projects| Japanese Intelligent Surgical Instrument Project]] [AIST] (Noby Hata, Chinzei, Hong)&lt;br /&gt;
#microSlicer3:Doing microscopy image analysis with Slicer3[Ohio State U](Kishore M., Raghu M., Brad Davis,Stephen Aylward, Steve Pieper)&lt;br /&gt;
#fmri image analysis with Slicer 3[Ohio State U](Firdaus J.,Raghu M., Luis Ibanez,Steve Pieper, Wendy Plesniak)&lt;br /&gt;
#[[2008_Winter_Project_Week:Resampling_DTIs_with_Slicer3|Resampling DTIs with Slicer 3]] (Francois Budin, Sylvain Bouix)&lt;br /&gt;
&lt;br /&gt;
== Dates.Venue.Registration ==&lt;br /&gt;
&lt;br /&gt;
'''Dates:''' &lt;br /&gt;
* The All Hands Meeting and External Advisory Board Meeting will be held on '''Thursday, January 10th'''.  &lt;br /&gt;
* Project Activities will be held rest of the week between '''Monday, January 7th and Friday, January 11th'''.&lt;br /&gt;
&lt;br /&gt;
'''Venue:''' The venue for the meeting is [http://www.marriott.com/hotels/travel/slccc-salt-lake-city-marriott-city-center/ Marriot City Center, Salt Lake City, Utah] Mariott City Center, Salt Lake City, Utah. [http://marriott.com/property/meetingsandevents/floorplans/slccc (Floorplan)]. To reserve rooms at the meeting rate of $129/night, please call the hotel at 1-801-961-8700 or 1-866-961-8700 (toll free) and mention that you are attending the NAMIC meeting.  Please note that we do need attendees to use this hotel in order to not incur additional charges for the use of conference rooms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt; '''Registration:''' We are charging a registration fee to all participants. The fee covers the costs of the facilities and food provided. In order to keep the fee low, we need to get a sufficient number of hotel nights by our participants. See above for more on this. Please click [http://www.sci.utah.edu/namic2008/registration.html '''here'''] for online registration. This registration must be completed by Friday, December 14, 2007. &amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Please note that this information can also be found [[AHM_2008#Dates.Venue.Registration|here.]]&lt;br /&gt;
&lt;br /&gt;
([[Project Week Logistics Checklist|This is a checklist for the onsite planning items]])&lt;br /&gt;
&lt;br /&gt;
===Introduction to NA-MIC Project Week===&lt;br /&gt;
&lt;br /&gt;
Please read the introduction to these events [[Project_Events#Introduction|here]].&lt;br /&gt;
&lt;br /&gt;
=== Agenda===&lt;br /&gt;
&lt;br /&gt;
[[AHM_2008#Agenda|Agenda for AHM 2008 and Project Week]]&lt;br /&gt;
&lt;br /&gt;
=== Preparation ===&lt;br /&gt;
&lt;br /&gt;
# Please make sure that you are on the [http://public.kitware.com/cgi-bin/mailman/listinfo/na-mic-project-week na-mic-project-week mailing list]&lt;br /&gt;
# [[Engineering:TCON_2007#2007-11-29|November 29, 2007: Kickoff TCON#1 (w/ NA-MIC Engeering Core only) to discuss Projects and Assign/Verify Teams]]&lt;br /&gt;
# [[Engineering:TCON_2007#2007-12-06|December 6, 2007: TCON#2 with all participants to Assign/Verify Teams]]&lt;br /&gt;
# [[Engineering:TCON_2007#2007-12-13|December 13, 2007: TCON#3 with Breakout Session owners to review agendas]]&lt;br /&gt;
# [[Engineering:TCON_2007#2007-12-13|December 20, 2007: TCON#4 to discuss outstanding projects and teams]]&lt;br /&gt;
# [[Engineering:TCON_2007#2008-01-03|January 3, 2008: TCON#5 to discuss outstanding projects and teams]]&lt;br /&gt;
# December 20, 2007: Create a Wiki page per project (the participants must do this, hopefully jointly)&lt;br /&gt;
# January 3, 2008: Create a directory for each project on the [[Engineering:SandBox|NAMIC Sandbox]] (Zack)&lt;br /&gt;
##[https://www.kitware.com/Admin/SendPassword.cgi Ask Zack for a Sandbox account]&lt;br /&gt;
## Commit on each sandbox directory the code examples/snippets that represent our first guesses of appropriate methods. (Luis and Steve will help with this, as needed)&lt;br /&gt;
## Gather test images in any of the Data sharing resources we have (e.g. the BIRN). These ones don't have to be many. At least three different cases, so we can get an idea of the modality-specific characteristics of these images. Put the IDs of these data sets on the wiki page. (the participants must do this.)&lt;br /&gt;
## Setup nightly tests on a separate Dashboard, where we will run the methods that we are experimenting with. The test should post result images and computation time. (Zack)&lt;br /&gt;
# By December 17, 2008: [[2008_Winter_Project_Week_Template|Complete a templated wiki page for your project]]. Please do not edit the template page itself, but create a new page for your project and cut-and-paste the text from this template page.  If you have questions, please send an email to tkapur at bwh.harvard.edu.&lt;br /&gt;
# Please note that by the time we get to the project event, we should be trying to close off a project milestone rather than starting to work on one...&lt;br /&gt;
&lt;br /&gt;
== Previous Project Events ==&lt;br /&gt;
&lt;br /&gt;
A history of all the programming/project events in NA-MIC is available by following [[Project Events|this link]].&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14255</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14255"/>
		<updated>2007-08-07T16:08:53Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Convert tensor data between gradient space and ijk space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space).&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
Such transformations incur numerical errors. After both transformations the data is back in original gradient space and should be exactly the same as the data originally loaded, but this is not quite the case. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea how big this numerical error can be, the following inital test can be performed with the original file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14254</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14254"/>
		<updated>2007-08-07T16:06:57Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Convert tensor data between gradient space and ijk space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space).&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
Such transformations incur numerical errors. After both transformations the data is back in original gradient space and should be exactly the same as the data originally loaded, but this is not quite the case. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14253</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14253"/>
		<updated>2007-08-07T16:04:03Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space).&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
Such transformations incur a numerical error. That means, even though after both transformations the data in original gradient space should be exactly the same as the data originally loaded, this is not quite the case. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14252</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14252"/>
		<updated>2007-08-07T15:56:39Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. Paths to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14251</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14251"/>
		<updated>2007-08-07T15:53:35Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do this transformations automatically.&lt;br /&gt;
&lt;br /&gt;
A nrrd volume stores transformation information for the different coordinate systems. How fields &amp;quot;measurement frame&amp;quot;, &amp;quot;space directions&amp;quot; and the different coordinate systems are related, is depicted in the figure on the right by Gordon Kindlemann.&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14250</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14250"/>
		<updated>2007-08-07T15:46:36Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is to send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data already is in &amp;quot;Index space&amp;quot;.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14249</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14249"/>
		<updated>2007-08-07T15:43:42Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node when put back into Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14248</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14248"/>
		<updated>2007-08-07T15:42:21Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Basic Slicer-Matlab tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab. For conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. As an example, the volume is thresholded here:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14247</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14247"/>
		<updated>2007-08-07T15:36:22Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Matlab */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate his popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14246</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14246"/>
		<updated>2007-08-07T15:25:50Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Matlab */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14245</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14245"/>
		<updated>2007-08-07T14:01:32Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Convert tensor data between gradient space and ijk space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element. This is not a necessarliy a good measure for tensor integrity. Even though the element-wise relative difference might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14218</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14218"/>
		<updated>2007-08-06T21:13:30Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Convert tensor data between gradient space and ijk space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space);&lt;br /&gt;
This script compares tensors element by element which is not a good measure for tensor integrity. Even though the element-wise relative error might be very big, measures like trace of FA might still be very alike.&lt;br /&gt;
If the measurement frame is axis aligned, this test should give some result like that:&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14217</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14217"/>
		<updated>2007-08-06T21:02:44Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Convert tensor data between gradient space and ijk space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred. In part this is due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed with the originally file-loaded nrrd structure:&lt;br /&gt;
 tensor_first_to_ijk_then_back_to_gradient = transformationTestLoop(tensor_gradient_space)&lt;br /&gt;
This script compares tensors element by element which is not a good measure for tensor integrity. Even though the element-wise relative error might be very big, measures like trace of FA might still be very alike.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14216</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14216"/>
		<updated>2007-08-06T20:35:35Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Convert tensor data between gradient space and ijk space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The function changes the measurement frame matrix of the nrrd structure. The measurement frame is the rotation matrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure).&lt;br /&gt;
Now you could send this volume to Slicer, since it is in the correct space (the Slicer ijk space)&lt;br /&gt;
&lt;br /&gt;
*Convert data back into Gradient space: &lt;br /&gt;
 tensor_back_to_gradient_space = tensorTransformToGradientSpace(tensor_ijk_space, tensor_gradient_space.measurementframe )&lt;br /&gt;
The transformation function needs the original measurement frame matrix, otherwise the transformation obviously can't be done.&lt;br /&gt;
&lt;br /&gt;
When such transformations are done, a numerical error is incurred, in part due to matrix inversions, especially when the measurement frame is non trivial and tensor elements are very small. To give you an idea, how big this numerical error can be, the following inital test can be performed:&lt;br /&gt;
transformationTestLoop&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14215</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14215"/>
		<updated>2007-08-06T20:23:55Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Slicer-Matlab interface and tensor data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;br /&gt;
&lt;br /&gt;
==== Convert tensor data between gradient space and ijk space ====&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
*Load original file with loadNrrdStructure. The tensor data will be in diffusion gradient space.&lt;br /&gt;
  tensor_gradient_space = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
*Convert data into Slicer space:&lt;br /&gt;
 tensor_ijk_space = tensorTransformToSlicerSpace(tensor_gradient_space);&lt;br /&gt;
Depending on how big your volume is, this might take a while. The script iterates through all tensors and transforms them.&lt;br /&gt;
The measurement frame matrix of the nrrd structure is changed by this function. The measurement frame is the rotationmatrix that transforms a tensor into world space. When the tensor data is in ijk space, this matrix needs to be the inverse of the RASToIJK matrix (see Gordon's figure)&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14214</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14214"/>
		<updated>2007-08-06T20:14:34Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Slicer-Matlab interface and tensor data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. The path to these functions need to be added to the Matlab path.&lt;br /&gt;
 tensor = loadNrrdStructure('/projects/schiz/guest/kquintus/data/testVolumes/tensor/helix.nhdr')&lt;br /&gt;
&lt;br /&gt;
 tensor = &lt;br /&gt;
             content: 'helix'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-98.4375 -96.8750 -91.6667]&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
&lt;br /&gt;
This is how to save a nrrd volume: &lt;br /&gt;
 saveNrrdStructure('/var/tmp/tensor.nhdr', tensor)&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14213</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14213"/>
		<updated>2007-08-06T20:05:00Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Slicer-Matlab interface and tensor data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and create a Matlab structure according to the header information . The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the [http://teem.sourceforge.net/ teem library]. These functions need to be in the Matlab path.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14212</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14212"/>
		<updated>2007-08-06T19:58:23Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Slicer-Matlab interface and tensor data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When tensor data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. Also, the SlicerDaemon expects tensor data to be in LPS orientation.&lt;br /&gt;
The SlicerDaemon will not do any of these transformations.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;br /&gt;
&lt;br /&gt;
Some small and simple scripts that you might find useful to load nhdr files into Matlab and rotate tensor data into the space you want are provided:&lt;br /&gt;
&lt;br /&gt;
==== Load and save nrrd files in Matlab ====&lt;br /&gt;
&lt;br /&gt;
* saveNrrdStructure.m and loadNrrdStructure.m read or write a nrrd file and according to the header information create a Matlab structure. The scripts call the &amp;quot;nrrdLoad&amp;quot; and &amp;quot;nrrdSave&amp;quot; functions of the teem library. These functions need to be in the Matlab path.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14211</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14211"/>
		<updated>2007-08-06T19:29:23Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Coords-RAS.png|thumb|182px|right|NRRD fields for image orientation and measurement frame]]&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot;. The SlicerDaemon will not do this transformation.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14210</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14210"/>
		<updated>2007-08-06T19:11:39Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there are a couple of issues regarding tensor orientation that the user needs to be aware of. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered:&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;br /&gt;
When data is piped into Slicer using the SlicerDaemon, it is assumed this data is in &amp;quot;Index space&amp;quot; already, the SlicerDaemon will not do this transformation.&lt;br /&gt;
How measurement frame, space directions and the different coordinate systems are related, is depicted in this figure by Gordon Kindlemann:&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14209</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14209"/>
		<updated>2007-08-06T18:56:34Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: /* Slicer-Matlab interface and tensor data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there a couple of issues regarding tensor orientation need to be considered. &lt;br /&gt;
If the only thing you want to do is send a tensor volume from Slicer to Matlab, do some Matlab processing, and send the volume back to Slicer, tensor orientation should not be a problem.&lt;br /&gt;
But in case you want to send tensor volumes from other sources but Slicer from Matlab to Slicer, the following needs to be considered.&lt;br /&gt;
&lt;br /&gt;
In the original file itself, the tensor data usually lives in the &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good computational performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14208</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14208"/>
		<updated>2007-08-06T18:52:40Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab interface and tensor data ===&lt;br /&gt;
&lt;br /&gt;
When sending tensor data from Matlab to Slicer and vice versa, there a couple of issues regarding tensor orientation need to be considered. In the original file itself, the tensor data usually lives in the &amp;quot;diffusion-sensitizing gradient space&amp;quot;. When loading into Slicer3 though, the tensor data automatically gets transformed into so-called IJK-space, or &amp;quot;Index space&amp;quot;. This is necessary for good filter performance in Slicer3, since most ITK based filters require the data to be in ijk space.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14193</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14193"/>
		<updated>2007-08-06T15:42:54Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. Thanks to Dan Ellis for letting us incorporate the popen matlab code into Slicer.&lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, here the volume is thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
&lt;br /&gt;
* By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This command sends the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Tutorial for Slicer-Matlab interface for tensor data ===&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14192</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14192"/>
		<updated>2007-08-06T15:31:45Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
The resulting Matlab strucuture will looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, the volume can be thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This is the command to send the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14191</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14191"/>
		<updated>2007-08-06T15:30:48Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
The matlab strucuture for instance looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like that (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This command fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, the volume can be thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This is the command to send the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14190</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14190"/>
		<updated>2007-08-06T15:29:00Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The SlicerDaemon in combination with matlab scripts provided here support the exchange of scalar and tensor volumes between Slicer and Matlab that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a step by step tutorial how to send a volume from Slicer to Matlab and then from back from Matlab to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab and for conveniance change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled for your machine (this is not handled by cmake yet). This needs to be done only once in Matlab: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following command in Matlab, the Slicer volume named &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
The matlab strucuture for instance looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like this (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
Instead of typing the name the volume has in Slicer, you can choose the volume by its Slicer-id. The ids are given in the order volumes are loaded in Slicer. This ommand fetches the volume loaded first in Slicer:&lt;br /&gt;
 slicer_volume = getSlicerVolume(0)&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, the volume can be thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This is the command to send the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14189</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14189"/>
		<updated>2007-08-06T15:17:45Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The matlab toolbox in combination with the SlicerDaemon support the exchange of scalar and tensor volumes that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a short step by step tutorial how to send a volume first from Slicer to Matlab and then from Matlab abck to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab &lt;br /&gt;
* In Matlab, just for conveniance, change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled in Matlab for your machine (this is not handled by cmake yet). This needs to be done only once: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following commang in Matlab, a Slicer volume with name &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
The matlab strucuture for instance looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like this (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, the volume can be thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This is the command to send the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14168</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14168"/>
		<updated>2007-08-03T22:28:29Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only, and is subject to change as the API evolves.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The matlab toolbox in combination with the SlicerDaemon support the exchange of scalar and tensor volumes that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Basic Slicer-Matlab tutorial ===&lt;br /&gt;
Here a short step by step tutorial how to send a volume first from Slicer to Matlab and then from Matlab abck to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab &lt;br /&gt;
* In Matlab, just for conveniance, change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled in Matlab for your machine (this is not handled by cmake yet). This needs to be done only once: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following commang in Matlab, a Slicer volume with name &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
The matlab strucuture for instance looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like this (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, the volume can be thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This is the command to send the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14167</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14167"/>
		<updated>2007-08-03T22:27:13Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only, and is subject to change as the API evolves.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors project ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The matlab toolbox in combination with the SlicerDaemon support the exchange of scalar and tensor volumes that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab tutorial ===&lt;br /&gt;
Here a short step by step tutorial how to send a volume first from Slicer to Matlab and then from Matlab abck to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab &lt;br /&gt;
* In Matlab, just for conveniance, change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled in Matlab for your machine (this is not handled by cmake yet). This needs to be done only once: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following commang in Matlab, a Slicer volume with name &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
The matlab strucuture for instance looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like this (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, the volume can be thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This is the command to send the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
==== Tensor transformation issues ====&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14166</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14166"/>
		<updated>2007-08-03T22:23:43Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
 &lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only, and is subject to change as the API evolves.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code are available.  &lt;br /&gt;
&lt;br /&gt;
This [http://wiki.na-mic.org/Wiki/index.php/Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors projects ] has been worked on during the NAMIC project week 2007.&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The matlab toolbox in combination with the SlicerDaemon support the exchange of scalar and tensor volumes that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab tutorial ===&lt;br /&gt;
Here a short step by step tutorial how to send a volume first from Slicer to Matlab and then from Matlab abck to Slicer:&lt;br /&gt;
&lt;br /&gt;
* Start Slicer3 with parameter &amp;quot;--daemon&amp;quot; and load the (scalar or tensor) volume you want to send to Matlab.&lt;br /&gt;
* Start Matlab &lt;br /&gt;
* In Matlab, just for conveniance, change into the &amp;quot;Matlab&amp;quot; subdirectory of the SlicerDaemon module in Slicer3 (something like ../Slicer3/Modules/SlicerDaemon/Matlab) &lt;br /&gt;
* Initally, the popen C functions need to be compiled in Matlab for your machine (this is not handled by cmake yet). This needs to be done only once: &lt;br /&gt;
 mex popen/popenw.c&lt;br /&gt;
 mex popen/popenr.c&lt;br /&gt;
* Typing the following commang in Matlab, a Slicer volume with name &amp;quot;wcase1.nhdr&amp;quot; will be piped into a Matlab structure called &amp;quot;slicer_volume&amp;quot;:&lt;br /&gt;
 slicer_volume = getSlicerVolume('wcase1.nhdr')&lt;br /&gt;
The matlab strucuture for instance looks like this (for a scalar volume):&lt;br /&gt;
 slicer_volume = &lt;br /&gt;
            content: 'wcase1.nhdr'&lt;br /&gt;
               type: 'short'&lt;br /&gt;
          dimension: 3&lt;br /&gt;
              space: 'right-anterior-superior'&lt;br /&gt;
              sizes: [256 256 124]&lt;br /&gt;
             endian: 'little'&lt;br /&gt;
           encoding: 'raw'&lt;br /&gt;
        spaceorigin: [119.5310 -92.2500 119.5310]&lt;br /&gt;
         spaceunits: {'mm'  'mm'  'mm'}&lt;br /&gt;
              kinds: {'space'  'space'  'space'}&lt;br /&gt;
               data: [256x256x124 int16]&lt;br /&gt;
    spacedirections: [3x3 double] &lt;br /&gt;
or like this (for a tensor volume):&lt;br /&gt;
 slicer_volume =  &lt;br /&gt;
             content: 'helix.nhdr'&lt;br /&gt;
                type: 'float'&lt;br /&gt;
           dimension: 4&lt;br /&gt;
               space: 'right-anterior-superior'&lt;br /&gt;
               sizes: [7 64 32 12]&lt;br /&gt;
              endian: 'little'&lt;br /&gt;
            encoding: 'raw'&lt;br /&gt;
         spaceorigin: [-6.9386 -28.7554 -8.7247]&lt;br /&gt;
          spaceunits: {'&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'  '&amp;quot;mm&amp;quot;'}&lt;br /&gt;
               kinds: {'3D-masked-symmetric-matrix'  'space'  'space'  'space'}&lt;br /&gt;
                data: [4-D single]&lt;br /&gt;
     spacedirections: [3x3 double]&lt;br /&gt;
    measurementframe: [3x3 double]&lt;br /&gt;
          centerings: {'???'  'cell'  'cell'  'cell'}&lt;br /&gt;
&lt;br /&gt;
All volumes that come out of Slicer are in 'right-anterior-superior' orientation, have 'raw' encoding, and 'little' endian. Even if the original file loaded into Slicer had other header parameters.&lt;br /&gt;
&lt;br /&gt;
* Now the volume data can be processed in Matlab. Just for example, the volume can be thresholded:&lt;br /&gt;
 slicer_volume.data(slicer_volume.data &amp;gt; 100) = 0;&lt;br /&gt;
By changing the field &amp;quot;content&amp;quot;, the name of the volume node in Slicer will be changed:&lt;br /&gt;
 slicer_volume.content='Matlab_says_hi';&lt;br /&gt;
&lt;br /&gt;
* This is the command to send the volume back to Slicer:&lt;br /&gt;
 putSlicerVolume(slicer_volume)&lt;br /&gt;
==== Tensor transformation issues ====&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data.&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14164</id>
		<title>Slicer3:Slicer Daemon</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer3:Slicer_Daemon&amp;diff=14164"/>
		<updated>2007-08-03T21:20:14Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Goals and Functionality =&lt;br /&gt;
&lt;br /&gt;
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 '[http://en.wikipedia.org/wiki/Daemon_%28computer_software%29 daemons]'.&lt;br /&gt;
&lt;br /&gt;
= Server Implementation =&lt;br /&gt;
&lt;br /&gt;
The file &lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerd.tcl?view=log slicerd.tcl] implements the server side functionality.&lt;br /&gt;
&lt;br /&gt;
By default it listens for connections on port 18943.&lt;br /&gt;
&lt;br /&gt;
= Clients =&lt;br /&gt;
&lt;br /&gt;
== Tcl ==&lt;br /&gt;
&lt;br /&gt;
Two utilities are provided:&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerget.tcl?view=log slicerget.tcl] is used to read volumes out of slicer.  The volume is written to the stdout of the slicerget command in nrrd format.&lt;br /&gt;
&lt;br /&gt;
* [http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Tcl/slicerput.tcl?view=log 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.&lt;br /&gt;
&lt;br /&gt;
Some sample commands (assumes your PATH is correctly set to include unu, slicerget and slicerput):&lt;br /&gt;
&lt;br /&gt;
 # a noop -- just copy image onto itself&lt;br /&gt;
 slicerget.tcl 1 | slicerput.tcl noop&lt;br /&gt;
&lt;br /&gt;
 # put external data into slicer&lt;br /&gt;
 unu 1op abs -i d:/data/bunny-small.nrrd | slicerput.tcl&lt;br /&gt;
&lt;br /&gt;
 # run an external command and put the data back into slicer&lt;br /&gt;
 slicerget.tcl 1 | unu 1op abs -i - slicerput.tcl abs&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import numpy&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
im = n.getImage()&lt;br /&gt;
n.setImage( im * im )&lt;br /&gt;
&lt;br /&gt;
s.put(n, 'newImage')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import slicerd&lt;br /&gt;
import pylab&lt;br /&gt;
&lt;br /&gt;
s = slicerd.slicerd()&lt;br /&gt;
&lt;br /&gt;
n = s.get(0)&lt;br /&gt;
&lt;br /&gt;
slice = n.getImage()[16,:,:]&lt;br /&gt;
pylab.imshow(slice)&lt;br /&gt;
pylab.show()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matlab ==&lt;br /&gt;
''Note: this is initial documentation only, and is subject to change as the API evolves.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.na-mic.org/ViewVC/index.cgi/trunk/Modules/SlicerDaemon/Matlab/ Matlab based] versions of Slicer Daemon client code is available.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Matlab scripts getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data. &lt;br /&gt;
&lt;br /&gt;
The matlab toolbox in combination with the SlicerDaemon support the exchange of scalar and tensor volumes that are in orientation right-anterior-superior or left-posterior-superior. DWI volumes and other orientations are not supported yet.&lt;br /&gt;
&lt;br /&gt;
=== Slicer-Matlab tutorial ===&lt;br /&gt;
&lt;br /&gt;
==== Tensor transformation issues ====&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function volume = getSlicerVolume( id_or_name )&lt;br /&gt;
&lt;br /&gt;
% This is an example script that shows how to establish a reading pipe to a&lt;br /&gt;
% running slicer daemon (start Slicer3 with option --daemon).&lt;br /&gt;
% These steps have to be done to adapt the script to your environment:&lt;br /&gt;
% - matlab extentions &amp;quot;popenr&amp;quot; and &amp;quot;popenw&amp;quot; have to be compiled for your&lt;br /&gt;
%   machine: cd into $SLICER_HOME/Modules/SlicerDaemon/matlab/popen , and&lt;br /&gt;
%   do &amp;quot;mex popenr.c&amp;quot; and &amp;quot;mex popenw.c&amp;quot; in matlab.&lt;br /&gt;
% - make sure you add the path to popen&lt;br /&gt;
% - make sure to add the path to the matlab scripts in &lt;br /&gt;
%   $SLICER_HOME/Modules/SlicerDaemon/Tcl&lt;br /&gt;
%&lt;br /&gt;
% returns a struct with image data from slicer volume with id &amp;quot;id&amp;quot; or&lt;br /&gt;
% name &amp;quot;name&amp;quot; and image information according to the nrrd format.&lt;br /&gt;
&lt;br /&gt;
% add path for popen&lt;br /&gt;
cpath = pwd;&lt;br /&gt;
cd('popen');&lt;br /&gt;
pName = pwd;&lt;br /&gt;
addpath (pName);&lt;br /&gt;
&lt;br /&gt;
% find slicerget.tcl script&lt;br /&gt;
cd( cpath );&lt;br /&gt;
cd('../Tcl');&lt;br /&gt;
pScript = pwd;&lt;br /&gt;
cd( cpath );&lt;br /&gt;
&lt;br /&gt;
if (isa(id_or_name,'numeric')) &lt;br /&gt;
   % fprintf('The id is: %d.\n',id_or_name);&lt;br /&gt;
    cmd_r = sprintf('%s/slicerget.tcl %d',pScript, id_or_name);&lt;br /&gt;
elseif (isa(id_or_name,'char'))&lt;br /&gt;
   % fprintf('The name is: %s.\n',id_or_name);&lt;br /&gt;
    cmd_r = sprintf('%s/slicerget.tcl %s',pScript, id_or_name);&lt;br /&gt;
else&lt;br /&gt;
    fprintf('Usage: getSlicerVolume(id) or getSlicerVolume(name).\n');&lt;br /&gt;
    exit;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p_r = popenr(cmd_r);&lt;br /&gt;
if p_r &amp;lt; 0&lt;br /&gt;
    error(['Error running popenr(',cmd_r,')']);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
volume = preadNrrd(p_r);&lt;br /&gt;
&lt;br /&gt;
% close pipe&lt;br /&gt;
popenr(p_r,-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Slicer:Developer_Meetings:20070716&amp;diff=13583</id>
		<title>Slicer:Developer Meetings:20070716</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Slicer:Developer_Meetings:20070716&amp;diff=13583"/>
		<updated>2007-07-17T20:08:39Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Demo / Training session for PNL group to start using slicer3.  This is a follow up on an action item defined at  [[Slicer:Developer_Meetings:20070612 | an earlier meeting]].  The goal of this session is not to get 'first impressions' but to give PNL users the exposure and instructions they need in order to try some meaningful tasks.  Slicer3 is not expected to replace all the features currently used in slicer2.6 but there should be enough functionality that some manual segmentation tasks can be undertaken.&lt;br /&gt;
&lt;br /&gt;
Having PNL users with direct experience with the system will help make [[Slicer3:EditorUsabilitySessions | our usability plans]] more concrete.&lt;br /&gt;
&lt;br /&gt;
== Attendees ==&lt;br /&gt;
&lt;br /&gt;
*Steve Pieper&lt;br /&gt;
*Nicole Aucoin&lt;br /&gt;
*Katharina Quintus&lt;br /&gt;
*Wendy Plesniak&lt;br /&gt;
*Katie Hayes&lt;br /&gt;
*Sonia Pujol&lt;br /&gt;
*Usman Khan&lt;br /&gt;
*Doug Markant&lt;br /&gt;
*Douglas Terry&lt;br /&gt;
*Aristotle Voineskos&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
* Slicer3 for PNL users&lt;br /&gt;
** transfer of knowledge so can use new functions as they are added&lt;br /&gt;
** PNL will make an internal wiki page with notes&lt;br /&gt;
** we can make a tagged version for specific use cases as they start working well&lt;br /&gt;
** Katie will make a nightly build available in /projects/... for testing&lt;br /&gt;
*Realignment module&lt;br /&gt;
**pass in multiple volumes?&lt;br /&gt;
**everything under a transform gets resampled?&lt;br /&gt;
**requires being able to pass in a scene, most likely&lt;br /&gt;
*Demo&lt;br /&gt;
**test import of slicer2 xml files&lt;br /&gt;
**slices mode versus Axi/Sag/Cor&lt;br /&gt;
**no vtkAG module, will use ITK filters (may be issues, get previously done testing feedback from PNL group)&lt;br /&gt;
**how to composite lots of label volumes into one? Can load in lots of volumes at once, need selection support for applying batch processes&lt;br /&gt;
**showed scene snapshots, view modes, integrated save&lt;br /&gt;
**editor module current implementation versus future icon based interface&lt;br /&gt;
*revisit this subject at the next slicer dev meeting in two weeks&lt;br /&gt;
*Katharina will collect bugs from the group (via wiki page?), bring to an in person meeting with a core developer, who will either fix things on the spot or submit it to the bug tracker and assign it to the correct person&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12912</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12912"/>
		<updated>2007-06-29T03:02:06Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|[[  Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
* adapted Slicer Matlab interface to recent changes in vtkNRRDReader&lt;br /&gt;
* added Matlab functions:&lt;br /&gt;
** load nrrd volume from file into a Matlab structure that also holds header information&lt;br /&gt;
** save Matlab nrrd structure to file&lt;br /&gt;
** transform tensor data from Slicer IJK space into diffusion gradient space and vice versa&lt;br /&gt;
* to do:&lt;br /&gt;
** replicate these functions in Teem library&lt;br /&gt;
** quantify error for IJK to gradient space transformation&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the Slicer Daemon enabled (either with the &amp;quot;--daemon&amp;quot; flag or by turning on the Daemon using he View-&amp;gt;Application Settings dialog's Slicer Options tab), a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
The Matlab pipeline client can be used to send data from Slicer to Matlab, where data can be processed making advantage of already existing code and powerful Matlab toolboxes. The data can then be sent back to Slicer for visualisation or further processing. No file I/O is necessary. This can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in Matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average tensors&lt;br /&gt;
** Smooth tensor fields&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
===Tensor transformation issues===&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, the vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates.&lt;br /&gt;
 &lt;br /&gt;
Tensors piped to Matlab by default will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after Matlab processing, no such transformation needs to be done. Besides, this transformation and especially the inverse transformation when putting data back into Slicer will introduce numerical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
===Issues with different coordinate conventions in Matlab versus Slicer ===&lt;br /&gt;
&lt;br /&gt;
The pipeline user in Matlab has to be aware of the fact that when the volume is visualized in Matlab, the image will appear to be transposed due to different coordiate conventions. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12909</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12909"/>
		<updated>2007-06-29T02:57:05Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|[[  Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
* adapted Slicer Matlab interface to recent changes in vtkNRRDReader&lt;br /&gt;
* added Matlab functions:&lt;br /&gt;
** load nrrd volume from file into a Matlab structure that also holds header information&lt;br /&gt;
** save Matlab nrrd structure to file&lt;br /&gt;
** transform tensor data from Slicer IJK space into diffusion gradient space and vice versa&lt;br /&gt;
* to do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the Slicer Daemon enabled (either with the &amp;quot;--daemon&amp;quot; flag or by turning on the Daemon using he View-&amp;gt;Application Settings dialog's Slicer Options tab), a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
The Matlab pipeline client can be used to send data from Slicer to Matlab, where data can be processed making advantage of already existing code and powerful Matlab toolboxes. The data can then be sent back to Slicer for visualisation or further processing. No file I/O is necessary. This can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in Matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average tensors&lt;br /&gt;
** Smooth tensor fields&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
===Tensor transformation issues===&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, the vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates.&lt;br /&gt;
 &lt;br /&gt;
Tensors piped to Matlab by default will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after Matlab processing, no such transformation needs to be done. Besides, this transformation and especially the inverse transformation when putting data back into Slicer will introduce numerical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
===Issues with different coordinate conventions in Matlab versus Slicer ===&lt;br /&gt;
&lt;br /&gt;
The pipeline user in Matlab has to be aware of the fact that when the volume is visualized in Matlab, the image will appear to be transposed due to different coordiate conventions. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12405</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12405"/>
		<updated>2007-06-22T19:44:51Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|[[  Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
The Matlab pipeline client can be used to send data from Slicer to Matlab, where data can be processed making advantage of already existing code and powerful Matlab toolboxes. The data can then be sent back to Slicer for visualisation or further processing. No file I/O is necessary. This can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in Matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average tensors&lt;br /&gt;
** Smooth tensor fields&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
===Tensor transformation issues===&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, the vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates.&lt;br /&gt;
 &lt;br /&gt;
Tensors piped to Matlab by default will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after Matlab processing, no such transformation needs to be done. Besides, this transformation and especially the inverse transformation when putting data back into Slicer will introduce numerical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
===Issues with different coordinate conventions in Matlab versus Slicer ===&lt;br /&gt;
&lt;br /&gt;
The pipeline user in Matlab has to be aware of the fact that when the volume is visualized in Matlab, the image will appear to be transposed due to different coordiate conventions. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12395</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12395"/>
		<updated>2007-06-22T19:09:25Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|[[  Image:SlicerMatlabPipeline.png|Slicer Matlab Pipeline Schema]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
The Matlab pipeline client can be used to send data from Slicer to Matlab, where data can be processed making advantage of already existing code and powerful Matlab toolboxes. The data can then be sent back to Slicer for visualisation or further processing. No file I/O is necessary. This can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in Matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average tensors&lt;br /&gt;
** Smooth tensor fields&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
===Tensor transformation issues===&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, the vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates.&lt;br /&gt;
 &lt;br /&gt;
Tensors piped to Matlab by default will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after Matlab processing, no such transformation needs to be done. Besides, this transformation and especially the inverse transformation when putting data back into Slicer will introduce numerical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
===Issues with different coordinate conventions in Matlab versus Slicer ===&lt;br /&gt;
&lt;br /&gt;
The pipeline user in Matlab has to be aware of the fact that in Matlab memory matrices are stored in the order &amp;quot;column first, then row&amp;quot;. This convertion differs from the convention is many other languages(C++ for example). That's why all volumes piped from Slicer memory to Matlab memory will appear to be rotated to the right by 90 degrees. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=File:SlicerMatlabPipeline.png&amp;diff=12381</id>
		<title>File:SlicerMatlabPipeline.png</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=File:SlicerMatlabPipeline.png&amp;diff=12381"/>
		<updated>2007-06-22T18:15:56Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: Slicer Matlab pipeline schema&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Slicer Matlab pipeline schema&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12355</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12355"/>
		<updated>2007-06-22T15:44:58Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
The Matlab pipeline client can be used to send data from Slicer to Matlab, where data can be processed making advantage of already existing code and powerful Matlab toolboxes. The data can then be sent back to Slicer for visualisation or further processing. No file I/O is necessary. This can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in Matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average tensors&lt;br /&gt;
** Smooth tensor fields&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
===Tensor transformation issues===&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, the vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates.&lt;br /&gt;
 &lt;br /&gt;
Tensors piped to Matlab by default will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after Matlab processing, no such transformation needs to be done. Besides, this transformation and especially the inverse transformation when putting data back into Slicer will introduce numerical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
===Issues with different coordinate conventions in Matlab versus Slicer ===&lt;br /&gt;
&lt;br /&gt;
The pipeline user in Matlab has to be aware of the fact that in Matlab memory matrices are stored in the order &amp;quot;column first, then row&amp;quot;. This convertion differs from the convention is many other languages(C++ for example). That's why all volumes piped from Slicer memory to Matlab memory will appear to be rotated to the right by 90 degrees. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12347</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12347"/>
		<updated>2007-06-22T15:33:11Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
The Matlab pipeline client can be used to send data from Slicer to Matlab, where data can be processed making advantage of already existing code and powerful Matlab toolboxes. The data can then be sent back to Slicer for visualisation or further processing. No file I/O is necessary. This can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in Matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average tensors&lt;br /&gt;
** Smooth tensor fields&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
===Tensor transformation issues===&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, the vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates.&lt;br /&gt;
 &lt;br /&gt;
Tensors piped to Matlab by default will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after Matlab processing, no such transformation needs to be done. Besides, this transformation and especially the inverse transformation when putting data back into Slicer will introduce numerical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
===Issues with different coordinate conventions in Matlab and Slicer ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12340</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12340"/>
		<updated>2007-06-22T15:24:46Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin respectively) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation for tensor data. &lt;br /&gt;
&lt;br /&gt;
The Matlab pipeline client can be used to send data from Slicer to Matlab, where data can be processed making advantage of already existing code and powerful Matlab toolboxes. The data can then be sent back to Slicer for visualisation or further processing. No file I/O is necessary. This can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in Matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average two tensors&lt;br /&gt;
** smoothing of tensor field (Marco's algorithm?)&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
====Tensor transformation issues====&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates. &lt;br /&gt;
Tensors piped to Matlab will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after processing in Matlab, no such transformations need to be done. To apply this transformation and afterwards the inverse transformation will introduce numberical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12319</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12319"/>
		<updated>2007-06-22T15:03:26Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
* BWH: Marc Niethammer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
* Provide tools to pipe volume data from Slicer3 memory to Matlab and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Finalize utilities that transform tensor data from Slicer's IJK space to the original gradient space and transform the data from gradient space back to Slicer's IJK space respectively.&lt;br /&gt;
* Quantify numerical error for these transformations.  &lt;br /&gt;
* Application testing: Get user feedback.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
Matlab pipeline client can be used to send data from a running slicer to Matlab, where the data can be used as input for whatever great algorithms you have implemented in matlab. The data can then be sent back to slicer for visualisations or further processing. No file I/O is necessary. Can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average two tensors&lt;br /&gt;
** smoothing of tensor field (Marco's algorithm?)&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
====Tensor transformation issues====&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates. &lt;br /&gt;
Tensors piped to Matlab will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after processing in Matlab, no such transformations need to be done. To apply this transformation and afterwards the inverse transformation will introduce numberical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12052</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12052"/>
		<updated>2007-06-21T00:21:24Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
To extend and test Matlab client for reading and writing tensor data from/to Slicer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Provide tools to pipe tensor data from Slicer3 memory to Matlab and back&lt;br /&gt;
&lt;br /&gt;
* Provide matlab tools for tensor transformation from IJK space to gradient space and the other way around&lt;br /&gt;
** Test if these transformations in matlab are consistent with vtkNRRDReader&lt;br /&gt;
** Quantify numerical error when transformation from ijk space to gradient space and back to ijk space is done. &lt;br /&gt;
&lt;br /&gt;
* Application testing: who has a nice matlab script that needs tensor data as input?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipeline tools for scalar data are ready to use&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that read out volumes to stdout or write to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
* Matlab scripts: getSlicerVolume.m and putSlicerVolume.m use Matlab extention [http://labrosa.ee.columbia.edu/matlab/popenrw.html popen] to connect to stdout(stdin) of the tcl client slicerget.tcl (slicerput.tcl respectively). The tcl client establishes a channel to the SlicerDaemon socket and requests(sends) data.&lt;br /&gt;
* flag in these scripts can be set to do/undo gradientSpace-&amp;gt;IJKspace transformation. &lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
Matlab pipeline client can be used to send data from a running slicer to Matlab, where the data can be used as input for whatever great algorithms you have implemented in matlab. The data can then be sent back to slicer for visualisations or further processing. No file I/O is necessary. Can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average two tensors&lt;br /&gt;
** smoothing of tensor field (Marco's algorithm?)&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
====Tensor transformation issues====&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters require data in ijk coordinates. &lt;br /&gt;
Tensors piped to Matlab will live in IJK-space, since this is where they are in Slicer memory. Assuming the dataset will be sent back to Slicer after processing in Matlab, no such transformations need to be done. To apply this transformation and afterwards the inverse transformation will introduce numberical errors due to matrix inversion.&lt;br /&gt;
&lt;br /&gt;
However, the Matlab user might wish to transform the data back to gradient space. Matlab tools are provided to perform transformations needed.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12047</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12047"/>
		<updated>2007-06-20T22:47:54Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
To extend and test Matlab client for reading and writing tensor data from/to Slicer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipe data from running Slicer3 to Matlab and back to do quick prototyping with Matlab&lt;br /&gt;
&lt;br /&gt;
* Provide matlab tools for tensor transformation from IJK space to gradient space and the other way around&lt;br /&gt;
** Test if these transformations in matlab are consistent with vtkNRRDReader&lt;br /&gt;
** Quantify numerical error when transformation from ijk space to gradient space and back to ijk space is done. &lt;br /&gt;
&lt;br /&gt;
* Application testing&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
When Slicer is started with the &amp;quot;--daemon&amp;quot; flag, a server socket is created that is listening and waiting for new connections. This network service can be used to connect to an instance of Slicer and access the MRML scene or other objects in Slicer memory.&lt;br /&gt;
Several clients have been written or are beeing worked on at the moment:&lt;br /&gt;
* Tcl scripts that reads out volumes to stdout or writes to stdin &lt;br /&gt;
* Python based clients&lt;br /&gt;
* Matlab clients&lt;br /&gt;
The [http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page] provides more details.&lt;br /&gt;
&lt;br /&gt;
===The Matlab client===&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
&lt;br /&gt;
Matlab pipeline client can be used to send data from a running slicer to Matlab, where the data can be used as input for whatever great algorithms you have implemented in matlab. The data can then be sent back to slicer for visualisations or further processing. No file I/O is necessary. Can be very useful since a lot of methods or algorithms are first prototyped in Matlab.&lt;br /&gt;
Ideas what can be done easily in matlab while Slicer does not have the functionality yet:&lt;br /&gt;
* Tensors:&lt;br /&gt;
** Thresholding&lt;br /&gt;
** Do tensor statistics after masking tensor with labelmap&lt;br /&gt;
** Average two tensors&lt;br /&gt;
** smoothing of tensor field (Marco's algorithm?)&lt;br /&gt;
*Scalars:&lt;br /&gt;
** plot histogram (that allows to quantify, at the moment slicer-histograms are not associated with numbers )&lt;br /&gt;
&lt;br /&gt;
====Tensor transformation issues====&lt;br /&gt;
&lt;br /&gt;
When tensors are loaded into Slicer, the vtkNRRDReader performs transformation from diffusion gradient space into image space (IJK space). This is done to improve performance since most itk-filters need the data to be in ijk space. &lt;br /&gt;
Tensors that are piped to The decision has been made toSlicer &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
	<entry>
		<id>https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12045</id>
		<title>Projects/Slicer3/2007 Project Week Slicer Matlab Pipeline for scalars and tensors</title>
		<link rel="alternate" type="text/html" href="https://www.na-mic.org/w/index.php?title=Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors&amp;diff=12045"/>
		<updated>2007-06-20T21:15:34Z</updated>

		<summary type="html">&lt;p&gt;Kquintus: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
|[[Image:ProjectWeek-2007.png|thumb|320px|Return to [[2007_Programming/Project_Week_MIT|Project Week Main Page]] ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
===Key Investigators===&lt;br /&gt;
* BWH: Katharina Quintus&lt;br /&gt;
* Isomics: Steve Pieper&lt;br /&gt;
* BWH: Sylvain Bouix&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Objective&amp;lt;/h1&amp;gt;&lt;br /&gt;
To improve and test extend the pipeline for tensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 27%; float: left; padding-right: 3%;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Approach, Plan&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pipe data from running Slicer3 to Matlab and back to do quick prototyping with Matlab&lt;br /&gt;
&lt;br /&gt;
* Provide matlab tools for tensor transformation from IJK space to gradient space and the other way around&lt;br /&gt;
** Test if these transformations in matlab are consistent with vtkNRRDReader&lt;br /&gt;
** Quantify numerical error when transformation from ijk space to gradient space and back to ijk space is done. &lt;br /&gt;
&lt;br /&gt;
* Application testing&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width: 40%; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Progress&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear: both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
[http://wiki.na-mic.org/Wiki/index.php/Slicer3:Slicer_Daemon Slicer Deamon Wiki page]&lt;br /&gt;
&lt;br /&gt;
=Additional Information=&lt;br /&gt;
&lt;br /&gt;
====Introduction====&lt;br /&gt;
&lt;br /&gt;
* bla&lt;br /&gt;
&lt;br /&gt;
* blu&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[2007_Programming/Project_Week_MIT|Back to Project week]]&lt;/div&gt;</summary>
		<author><name>Kquintus</name></author>
		
	</entry>
</feed>