Difference between revisions of "OpenIGTLink/Matlab"
Line 6: | Line 6: | ||
This project is a generalization of [[Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors | Slicer Matlab Pipeline project]] in the 2007 NA-MIC Project Week. | This project is a generalization of [[Projects/Slicer3/2007_Project_Week_Slicer_Matlab_Pipeline_for_scalars_and_tensors | Slicer Matlab Pipeline project]] in the 2007 NA-MIC Project Week. | ||
+ | |||
+ | |||
+ | [[Video:OpenIGTLink_Matlab_1way.mov]] | ||
=How does it work?= | =How does it work?= |
Revision as of 00:29, 17 June 2010
Home < OpenIGTLink < MatlabContents
About the project
The objective of this project is to provide OpenIGTLink interface for Matlab / Octave to support research and development in image guided therapy (IGT). Matlab and Octave are widely used for prototyping image and signal processing algorithms. They also offer many powerful function sets to handle matrix and coordinate data, which is useful to test and analyze coordinate data exported from tracking and robotic devices. The OpenIGTLink interface for Matlab / Octave allows importing and exporting several types of data that can be handled in the OpenIGTLink protocol in a Matlab / Octave environment. It provides a rapid prototyping environment, which many researchers and engineers are already familiar with.
This project is a generalization of Slicer Matlab Pipeline project in the 2007 NA-MIC Project Week.
Video:OpenIGTLink_Matlab_1way.mov
How does it work?
The OpenIGTLink Matlab interface is implemented as a set of MEX Files, which are C/C++ source codes called from Matlab. Those MEX files simply receive data from Matlab, connect to the OpenIGTLink receiver, serialize the data in an appropriate format using the OpenIGTLink Library, and send it to the receiver.
The usage of the interface is quite simple. The following example Matlab code is sending trancking data to the receiver waiting at port #18944 on the localhost.
%%% affine transform matrix M = [1.0, 0.0, 0.0, 0.0; 0.0,-1.0, 0.0, 0.0; 0.0, 0.0, 1.0, 0.0; 0.0, 0.0, 0.0, 1.0]; IMGDATA.Type = 'TRANSFORM'; IMGDATA.Name = 'MatlabTrans'; IMGDATA.Trans = M; sd = igtlopen('localhost', 18944); r = igtlsend(sd, IMGDATA); igtlclose(sd);
For tracking data transfer:
%%% read image data fid = fopen('igtlTestImage1.raw', 'r'); I = fread(fid, [256 256], 'uint8')'; fclose(fid); %%% affine transform matrix M = [1.0, 0.0, 0.0, 0.0; 0.0,-1.0, 0.0, 0.0; 0.0, 0.0, 1.0, 0.0; 0.0, 0.0, 0.0, 1.0]; IMGDATA.Type = 'IMAGE'; IMGDATA.Name = 'MatlabImage'; IMGDATA.Image = I; IMGDATA.Trans = M; %%% send the image data through OpenIGTLink connection sd = igtlopen('localhost', 18944); r = igtlsend(sd, IMGDATA); igtlclose(sd);
Building OpenIGTLink Mex functions
Install the OpenIGTLink Library
The instruction can be found in OpenIGTLink/Library
Get the Matlab OpenIGTLink interface source code
The OpenIGTLink/Matlab interface is in the initial stage of development. The source code is available from NA-MIC SandBox repository at
http://svn.na-mic.org/NAMICSandBox/trunk/MatlabIGTL
Build MEX files
There are two ways to build Matlab OpenIGTLink interface:
Using CMake
CMake configuration (CMakeLists.txt) comes with Matlab OpenIGTLink interface. To build the interface with CMake in Linux/Mac OS X environment,
cd <working directory> svn co URL: http://svn.na-mic.org/NAMICSandBox/trunk/MatlabIGTL mkdir MatlabIGTL-build cd MatlabIGTL-build ccmake ../MatlabIGTL
This will launch Curses Interface for CMake. Press 'c' to configure and check the following parameters;
*MEX_COMPILER = (path to Matlab's mex command or Octave's mkoctfile) *OpenIGTLInk_DIR = (path to binary directory of OpenIGTLink)
Then press 'g' to generate a makefile. Press 'q' to quit the CMake interface screen. Once you find Makefile in the directory, run make. Several files with extension *.mex (or *.mex<arc-name>) will be generated.
Using Makefile
You need to have a MEX compiler or octave to the build MEX binaries. To build the binaries, you may need to edit the Makefile.
First substitute the path to the OpenIGTLink Library source and binary directories installed on your system:
### OpenIGTLink Library IGTLSRC= /projects/igtdev/tokuda/igtl/OpenIGTLink IGTLBLD= /projects/igtdev/tokuda/igtl/OpenIGTLink-build
If you use Maltab, specify the full path to the MEX compiler. You don't need to have any options to the MEX compiler.
MEX = /local/os-exact/pkg/Matlab71-64/bin/mex MEXOPT =
If you use Octave, specify the full path to the mkoctfile program and "--mex" option.
MEX = /Applications/Octave.app/Contents/Resources/bin/mkoctfile MEXOPT = --mex
Now you are ready to build your MEX file. Run make. If the MEX files are successfully built, you can find:
igtlclose.mex<arc-name> igtlopen.mex<arc-name> igtlsend.mex<arc-name>
Note that <arc-name> is the architecture name of your system.
Contact
We are not providing a support for this software, but questions and requests are always welcome. If you have any, please contact Junichi Tokuda at Brigham and Women's Hospital.