<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>There a many options to choose from to minimize memory. Some filter run in-place, and re-use the input buffer on the output.</div><div><br></div><div>Can you use the image buffer from ITK and import it into matlab? Does matlab not have the ability to import a buffer?</div><div><br></div><div>As Matt said this behavior that you are expecting is not required, and as I mentioned above sometimes not do able. However, based on the code you provided, it should be possible to modify this filter to do the correct grafting. If you create a patch, which adds to the exiting test for this filter this behavior, then submit it to gerrit, it would make it easier for someone to modify the filter to the desired behavior.</div><div><br></div><div>Brad</div><div><br><div><div>On May 24, 2013, at 7:16 PM, Ramón Casero Cañas &lt;<a href="mailto:rcasero@gmail.com">rcasero@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr">Hi all,<div><br></div><div style="">I think there may be some problem with some of the itk::ImageToImageFilter when one tries to graft a C++ array to be used as the filter's output, or at least with the way I do it.</div>
<div style=""><br></div><div style="">This was kindly reported by Peter Thalmann in [1], and I'm trying to help him. This is a problem that I had also noticed with a couple of other filters.</div><div style=""><br></div><div style="">
I have attached a minimal example of a C++ MEX file that creates a function that can be run from Matlab, with the CMake files to compile it. (I have tried this with ITK&nbsp;4.3.1).</div><div style=""><br></div><div style="">Save everything to directory test, and then build the example from the shell</div>
<div style=""><br></div><div style="">cd test</div><div style="">mkdir bin</div><div style="">cd bin</div><div style="">cmake ..</div><div style="">make install</div><div style=""><br></div><div style="">To run the example from Matlab,</div><div style="">
<br></div><div style="">cd test</div><div style="">% create a test binary square with a little hole</div><div style=""><div>im = zeros(15, 15, 'uint8');</div><div>im(3:13, 3:13) = 1;</div><div>im(7:8, 7) = 0;</div><div>im2 = itk_test(im);<br>
</div></div><div><br></div><div style="">This runs filter&nbsp;itk::VotingBinaryIterativeHoleFillingImageFilter on the image. The program outputs to the Matlab shell both the content of filter-&gt;GetOutput(), and the content of the Matlab output array. As we can see, the output is not being saved to the array</div>
<div style=""><br></div><div style=""><div>Filter result, reading from the filter</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>Filter result, reading from the Matlab output array</div>
<div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div>
<div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div>
<div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div></div><div style=""><br></div><div style=""><br></div><div style="">But this approach works for other filters. If we choose the Median filter instead: in ItkTestSimpleImFilter.cpp, ucomment</div>
<div style=""><br></div><div style=""><div>&nbsp; // typedef itk::MedianImageFilter&lt;ImageType, ImageType&gt;</div><div>&nbsp; // &nbsp; FilterType;</div><div><br></div><div style="">and comment out</div><div style=""><br></div><div style=""><div>&nbsp; typedef itk::VotingBinaryIterativeHoleFillingImageFilter&lt;ImageType&gt;</div>
<div>&nbsp; &nbsp; FilterType;</div></div></div><div><br></div><div>[...]</div><div><br></div><div><div>&nbsp; // filter parameters only for the VotingBinaryIterativeHoleFillingImageFilter</div><div>&nbsp; filter-&gt;SetMaximumNumberOfIterations(4);</div>
<div>&nbsp; filter-&gt;SetBackgroundValue(0);</div><div>&nbsp; filter-&gt;SetForegroundValue(1);</div><div>&nbsp; filter-&gt;SetMajorityThreshold(2);</div><div><br></div><div style="">then we can see that the array is actually being used as the filter's output</div>
<div style=""><br></div><div style=""><div>&gt;&gt; im2 = itk_test(im);</div><div>Filter result, reading from the filter</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0&nbsp;</div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div>
<div>Filter result, reading from the Matlab output array</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0&nbsp;</div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0&nbsp;</div></div><div><br></div>
<div style="">I have been looking at itkVotingBinaryIterativeHoleFillingImageFilter.hxx, and I was wondering whether the problem is in VotingBinaryIterativeHoleFillingImageFilter&lt; TInputImage &gt;</div><div>::GenerateData().</div>
<div><br></div><div style="">The filter works iteratively, doing</div><div style=""><br></div><div style=""><div>&nbsp; while ( m_CurrentNumberOfIterations &lt; m_MaximumNumberOfIterations )</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; filter-&gt;SetInput(input);</div>
<div>&nbsp; &nbsp; filter-&gt;Update();</div><div><br></div><div>&nbsp; &nbsp; m_CurrentNumberOfIterations++;</div><div>&nbsp; &nbsp; progress.CompletedPixel(); &nbsp; // not really a pixel but an iteration</div><div>&nbsp; &nbsp; this-&gt;InvokeEvent( IterationEvent() );</div>
<div><br></div><div>&nbsp; &nbsp; const unsigned int numberOfPixelsChangedInThisIteration =</div><div>&nbsp; &nbsp; &nbsp; filter-&gt;GetNumberOfPixelsChanged();</div><div>&nbsp; &nbsp; m_NumberOfPixelsChanged += numberOfPixelsChangedInThisIteration;</div>
<div><br></div><div>&nbsp; &nbsp; output = filter-&gt;GetOutput();</div><div>&nbsp; &nbsp; output-&gt;DisconnectPipeline();</div><div>&nbsp; &nbsp; input = output;</div><div>&nbsp; &nbsp; if ( numberOfPixelsChangedInThisIteration == 0 )</div><div>&nbsp; &nbsp; &nbsp; {</div><div>
&nbsp; &nbsp; &nbsp; break;</div><div>&nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; }</div><div>&nbsp; this-&gt;GraftOutput(output);</div><div><br></div><div><br></div><div style="">Here, output gets a&nbsp;DisconnectPipeline(). I have tried commenting that like out, rebuilding and reinstalling ITK, but it doesn't seem to make a difference.</div>
<div style=""><br></div><div style="">[1]&nbsp;<a href="https://groups.google.com/forum/?fromgroups#!topic/gerardus-users/pLH0iR0H74o">https://groups.google.com/forum/?fromgroups#!topic/gerardus-users/pLH0iR0H74o</a></div><div style="">
<br></div><div style="">Best regards,</div><div style=""><br></div><div style="">Ramon.</div></div><div><br></div><div><br></div><br clear="all"><div><br></div>-- <br>Dr. Ramón Casero Cañas<br><br>Oxford e-Research Centre (OeRC)<br>
University of Oxford<br>7 Keble Rd<br>Oxford OX1 3QG<br><br>tlf &nbsp; &nbsp; +44 (0) 1865 610739<br>web &nbsp; &nbsp; <a href="http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas" target="_blank">http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas</a><br>
photos &nbsp;<a href="http://www.flickr.com/photos/rcasero/" target="_blank">http://www.flickr.com/photos/rcasero/</a>
</div></div>
<span>&lt;CMakeLists.txt&gt;</span><span>&lt;FindMatlab.cmake&gt;</span><span>&lt;ItkTestSimpleImFilter.cpp&gt;</span><span>&lt;MatlabMakeMacros.cmake&gt;</span>_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></blockquote></div><br></div></body></html>