[Insight-users] How do you get a MATLAB variable to ITK?
gunnar at bwh.harvard.edu
gunnar at bwh.harvard.edu
Mon Apr 11 15:37:06 EDT 2005
Craig Davis wrote:
> I have a question concerning Matlab and ITK. How can one get a variable
> (i.e. image) from Matlab into ITk and then from ITK back into Matlab.
> Any helpful advice on this would be greatly appreciated.
The easiest way is to save the image to disk when going to and from ITK.
ITK and Matlab have a number of supported file formats in common, although
somewhat dependent on the range of values in the image.
The more complex solution is to build the ITK pipeline as a Matlab mex
file. In that case the image can be transferred from Matlab to ITK with
an ImportImageFilter and from ITK to Matlab by looping over the image and
copy the GetPixel() results into a Matlab array.
Attached is the source code for a Matlab mex file running an image through
the recursive Gaussian filter from ITK. Don't ask me how to build it,
however. I somehow managed to make myself a working but terribly messy
Makefile, but there ought to be a good way to do it too, which I hope
someone else can give some hints about.
(This example code is just intended to demonstrate the transfer of images
between Matlab and ITK. A more complex implementation where you can also
pass the filter parameters is available on request.)
/Gunnar Farnebäck
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itkRecursiveGaussianImageFilter.cxx
Type: text/x-c++src
Size: 2630 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050411/453e66c2/itkRecursiveGaussianImageFilter.cxx
More information about the Insight-users
mailing list