MatlabBridgeDesignx

gorgeousvassalSoftware and s/w Development

Nov 7, 2013 (3 years and 11 months ago)

124 views

MatlabBridge

extension for 3D Slicer

(high
-
level design)

Andras Lasso

Motivation

Matlab


Interactive console and
scripting


Has its own
“programming
language”,
simpler than C++


Good
plotting (1D
-
2D),
data
analysis capabilities


High
-
quality official toolboxes
and many user
-
contributed
algorithm libraries


Many people know it


Very good for prototyping
certain algorithms

3D Slicer


End
-
user application with a
rich graphical user interface


Specifically developed for
medical imaging


Strong 3D image visualization


Image processing, registration,
segmentation features


Algorithms run faster (if
implemented in C++)


Catching up to
Matlab

in
interactive scripting (Python
console, VTK,
SimpleITK
,
numpy
), but still more
complex, not as convenient

Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

2

-

Requirements


Running
Matlab

algorithms directly from 3D Slicer


Only basic
Matlab

programming experience
should be required (not C++, Python, etc.)


Simple graphical user interface definition


Simple install: should not be needed to compile
any code


Quick execution of the algorithms


Support of Win/Linux/Mac operating systems

Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

3

-

Design choices 1


Existing 3D Slicer extension options


C++ loadable module


Python scripted module


Command
-
line interface module (CLI)


Decision: CLI


Graphical user interface can be defined in XML


Any executable (with a compatible interface) can be
run


Inputs/outputs through files and command
-
line
interface are supported

Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

4

-

Design choices 2


Communication with
Matlab


Start
Matlab

to run a custom
Matlab

script


Windows dynamic data exchange (DDE) interface


OpenIGTLink interface


Decision: OpenIGTLink interface


Matlab

is started only at the first execution (takes
several ten seconds) then keeps running


OpenIGTLink is supported already by 3D Slicer


Available on all operating systems


Simple TCP/IP based protocol, can be easily
implemented in
Matlab

Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

5

-

Implementation


MatlabCommander

(CLI module, C++): helper module that
can start
Matlab

and send commands through OpenIGTLink


Matlab

command server: OpenIGTLink server implemented
fully in
Matlab

(using Java classes)


Matlab

convenience functions for parameter parsing and
file reading/writing


Proxy shell script (.bat file on Windows, .
sh

on Linux/Mac):
provide GUI description or run the
Matlab

function,
executable file that doesn’t require compilation (unlike
C++) and quick to start (unlike Python)


Matlab

module generator (Slicer loadable module):
manages configuration options (
Matlab

executable path,
etc.), generates skeleton modules the user’s convenience


Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

6

-

Implementation 1

Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

7

-

Slicer

Matlab

Matlab

commander

MyModule.m

(
Matlab

algorithm
implementation skeleton)

MyModule.xml

(CLI definition)

MyModule.bat

(acts as a CLI module)

Utility functions

getarg
,
setarg
,
nrrdread
,
nrrdwrite

Execute
Matlab

function

(using OpenIGTLink

STRING command)

Command

server

Read

Request
Matlab

function call

Slicer Execution
Model

Execute CLI
module

Temporary input
and output files

Read/Write

Read/Write

Execute
Matlab

function

Use for get/set inputs/outputs

Matlab

module
execution

Implementation 2

Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

8

-

Slicer

Matlab

module
generator

MyModule.m

(
Matlab

algorithm
implementation skeleton)

MyModule.xml

(CLI definition)

MyModule.bat

(acts as a CLI module)

Generate

Generate

Generate

The user updates only
the .m and .xml files

Matlab

module
generation

More information


Tutorial:
http://
www.slicer.org/slicerWiki/images/a/a7/Matla
bBridgeTutorial.pdf


Extension documentation:
http://www.slicer.org/slicerWiki/index.php/Documentation/N
ightly/Extensions/MatlabBridge


Contact: Andras Lasso (
lasso@cs.queensu.ca
)

Laboratory for Percutaneous Surgery (The Perk Lab)


Copyright © Queen’s University, 2013

-

9

-