<div dir="ltr">Hi,<br><br>I've included some algorithms developed with Matlab in my C++ software. The Matlab algorithms were translated to C++ using Matlab Coder.<br>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.<br>
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?<br><br>void ImageProcessing::CopyItkToMatlabImage(ImageProcessing::RealImageType::Pointer itkI, emxArray_real_T *matlabI)<br>
{<br> RealImageType::SizeType size = itkI->GetLargestPossibleRegion().GetSize();<br><br> for (int ii=0; ii < size[0]; ++ii)<br> for (int jj=0; jj < size[1]; ++jj)<br> {<br> matlabI->data[ii*size[0]+jj] = (real_T)itkI->GetBufferPointer()[ii*size[0]+jj];<br>
}<br>}<br><br><br><br>void ImageProcessing::CopyMatlabToItkImage(emxArray_real_T * matlabI, ImageProcessing::RealImageType::Pointer itkI)<br>{<br><br> int32_T *size = matlabI->size;<br> RealIteratorType out ( itkI, itkI->GetLargestPossibleRegion() );<br>
out.GoToBegin();<br><br> for (int ii=0; ii < size[0]; ++ii)<br> for (int jj=0; jj < size[1]; ++jj)<br> {<br> out.Set(matlabI->data[ii*size[0]+jj]);<br> ++out;<br> }<br>}<br><br>Thanks a lot<br>
<br>Luca<br clear="all"><div><font style="font-size:x-small"><br>
---</font><br><div><span style="font-size:x-small">----------------------------------------------------------------------------------------------------------</span></div></div>
</div>