[Community] [Insight-users] Cast itkImage to Matlab emxArray
    Luca Tersi 
    lucatersi at gmail.com
       
    Fri Oct 18 11:28:51 EDT 2013
    
    
  
Hi,
I've included some algorithms developed with Matlab in my C++ software. The
Matlab algorithms were translated to C++ using Matlab Coder.
I've some images that have to be passed back and forth from the itk
pipeline to the Matlab algorithm that work with emxArray data type.
I've made the following methods in order to copy the data, but is there any
better and faster method? Moreover, is it better to use iterators or access
the buffer directly?
void
ImageProcessing::CopyItkToMatlabImage(ImageProcessing::RealImageType::Pointer
itkI, emxArray_real_T *matlabI)
{
  RealImageType::SizeType size = itkI->GetLargestPossibleRegion().GetSize();
  for (int ii=0; ii < size[0]; ++ii)
    for (int jj=0; jj < size[1]; ++jj)
      {
        matlabI->data[ii*size[0]+jj] =
(real_T)itkI->GetBufferPointer()[ii*size[0]+jj];
      }
}
void ImageProcessing::CopyMatlabToItkImage(emxArray_real_T * matlabI,
ImageProcessing::RealImageType::Pointer itkI)
{
  int32_T *size = matlabI->size;
  RealIteratorType out ( itkI, itkI->GetLargestPossibleRegion() );
  out.GoToBegin();
  for (int ii=0; ii < size[0]; ++ii)
    for (int jj=0; jj < size[1]; ++jj)
      {
        out.Set(matlabI->data[ii*size[0]+jj]);
        ++out;
      }
}
Thanks a lot
Luca
---
----------------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20131018/b3ab2d1d/attachment.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users
    
    
More information about the Community
mailing list