<div dir="ltr">Hi,<br><br>I&#39;ve included some algorithms developed with Matlab in my C++ software. The Matlab algorithms were translated to C++ using Matlab Coder.<br>I&#39;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&#39;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-&gt;GetLargestPossibleRegion().GetSize();<br><br>  for (int ii=0; ii &lt; size[0]; ++ii)<br>    for (int jj=0; jj &lt; size[1]; ++jj)<br>      {<br>        matlabI-&gt;data[ii*size[0]+jj] = (real_T)itkI-&gt;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-&gt;size;<br>  RealIteratorType out ( itkI, itkI-&gt;GetLargestPossibleRegion() );<br>

  out.GoToBegin();<br><br>  for (int ii=0; ii &lt; size[0]; ++ii)<br>    for (int jj=0; jj &lt; size[1]; ++jj)<br>      {<br>        out.Set(matlabI-&gt;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>