<div dir="ltr"><div><div>It works like a charm.<br></div>Thank you<br></div>Luca<br></div><div class="gmail_extra"><br clear="all"><div><font style="font-size:x-small"><br>
---</font><br><div><span style="font-size:x-small">----------------------------------------------------------------------------------------------------------</span></div></div>
<br><br><div class="gmail_quote">On 18 October 2013 17:36, Bradley Lowekamp <span dir="ltr"><<a href="mailto:brad@lowekamp.net" target="_blank">brad@lowekamp.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hello,<div><br></div><div>The GetBufferPointer is a method, and I would try to avoid that in a tight loop.</div><div><br></div><div>Here is a recent implementation to efficiently copy ITK regions:</div>
<div><a href="https://github.com/Kitware/ITK/blob/master/Modules/Core/Common/include/itkImageAlgorithm.hxx#L137" target="_blank">https://github.com/Kitware/ITK/blob/master/Modules/Core/Common/include/itkImageAlgorithm.hxx#L137</a></div>
<div><br></div><div>We have found that std::copy is a very robust and efficient way to copy the buffers with modern compilers. It can even work when a conversion is needed.</div><div><br></div><div>If you have validated the buffer is continuous and is the correct type and size. I would recommend just getting the raw buffer pointer and using std::copy. It may be up to 10-100X faster than your implementation below.</div>
<div><br></div><div><br><div><div><div class="h5"><div>On Oct 18, 2013, at 11:28 AM, Luca Tersi <<a href="mailto:lucatersi@gmail.com" target="_blank">lucatersi@gmail.com</a>> wrote:</div><br></div></div><blockquote type="cite">
<div><div class="h5"><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></div></div>
_____________________________________<br>Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>Kitware offers ITK Training Courses, for more information visit:<br><a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br><br>Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div></div></blockquote></div><br></div>