[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://www.itk.org/pipermail/insight-users/attachments/20131018/b3ab2d1d/attachment.htm>
More information about the Insight-users
mailing list