[Insight-users] Deriving itk::Image to natively support Matlab arrays

Ramón Casero Cañas rcasero at gmail.com
Wed Aug 10 06:37:51 EDT 2011


Hi all,

My question in short is whether it's possible (and not too hard) to 
derive itk::Image so that it can directly process an image passed by Matlab.

Here's the background to my question:


I have been building a project ItkToolbox to run ITK filters and warps 
from Matlab [1], a bit like MATITK [2].


The main issue I find is that MEX, the Matlab C++ interface, passes the 
input image as an array, e.g.

   const double *im = (double *)mxGetData(prhs[0]);

whereas ITK needs images in itk::Image format.


Right now, first I have to copy the image from Matlab to itk::Image, 
using RegionType and ImageRegionIterator, as described in the ITK User 
Guide. To avoid cluttering this email, here's a permlink to the 
CopyMatlabInputToItkImage() method that I wrote to do this

http://code.google.com/p/gerardus/source/browse/tags/release-0.5.0/matlab/ItkToolbox/MexBaseFilter.cpp#82

Then I run the ITK filter, and copy the result back to Matlab.


But I think it would be a lot more efficient if the copying steps could 
be avoided. That is, if it was possible to create something like

<CODE>
template < TPixel, VImageDimension >
class MatlabImage : public itk::Image< TPixel, VImageDimension > {

   // some code here

}
</CODE>


that simply takes the MEX pointer, e.g.

<CODE>
MatlabImage<double, 3> itkIm = MatlabImage<double, 3>::New();
itkImage->GetPointerToData(im);
</CODE>



Is this something doable? Is it really difficult to do? I'd be very 
grateful for any advice and guidance.

[1] 
http://code.google.com/p/gerardus/source/browse/trunk/matlab/#matlab%2FItkToolbox
[2] http://matitk.cs.sfu.ca/


Best regards,

Ramon.




-- 
Dr. Ramón Casero Cañas

Computational Biology
Department of Computer Science
University of Oxford
Wolfson Building, Parks Rd
Oxford OX1 3QD

tlf     +44 (0) 1865 610737
web     http://web.comlab.ox.ac.uk/people/Ramon.CaseroCanas
photos  http://www.flickr.com/photos/rcasero/


More information about the Insight-users mailing list