<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 <<a href="mailto:rcasero@gmail.com">rcasero@gmail.com</a>> 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 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 itk::VotingBinaryIterativeHoleFillingImageFilter on the image. The program outputs to the Matlab shell both the content of filter->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 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </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 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div>
<div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div>
<div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </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> // typedef itk::MedianImageFilter<ImageType, ImageType></div><div> // FilterType;</div><div><br></div><div style="">and comment out</div><div style=""><br></div><div style=""><div> typedef itk::VotingBinaryIterativeHoleFillingImageFilter<ImageType></div>
<div> FilterType;</div></div></div><div><br></div><div>[...]</div><div><br></div><div><div> // filter parameters only for the VotingBinaryIterativeHoleFillingImageFilter</div><div> filter->SetMaximumNumberOfIterations(4);</div>
<div> filter->SetBackgroundValue(0);</div><div> filter->SetForegroundValue(1);</div><div> filter->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>>> 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 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 </div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </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 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div>
<div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </div><div>0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div><div>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </div></div><div><br></div>
<div style="">I have been looking at itkVotingBinaryIterativeHoleFillingImageFilter.hxx, and I was wondering whether the problem is in VotingBinaryIterativeHoleFillingImageFilter< TInputImage ></div><div>::GenerateData().</div>
<div><br></div><div style="">The filter works iteratively, doing</div><div style=""><br></div><div style=""><div> while ( m_CurrentNumberOfIterations < m_MaximumNumberOfIterations )</div><div> {</div><div> filter->SetInput(input);</div>
<div> filter->Update();</div><div><br></div><div> m_CurrentNumberOfIterations++;</div><div> progress.CompletedPixel(); // not really a pixel but an iteration</div><div> this->InvokeEvent( IterationEvent() );</div>
<div><br></div><div> const unsigned int numberOfPixelsChangedInThisIteration =</div><div> filter->GetNumberOfPixelsChanged();</div><div> m_NumberOfPixelsChanged += numberOfPixelsChangedInThisIteration;</div>
<div><br></div><div> output = filter->GetOutput();</div><div> output->DisconnectPipeline();</div><div> input = output;</div><div> if ( numberOfPixelsChangedInThisIteration == 0 )</div><div> {</div><div>
break;</div><div> }</div><div> }</div><div> this->GraftOutput(output);</div><div><br></div><div><br></div><div style="">Here, output gets a 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] <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 +44 (0) 1865 610739<br>web <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 <a href="http://www.flickr.com/photos/rcasero/" target="_blank">http://www.flickr.com/photos/rcasero/</a>
</div></div>
<span><CMakeLists.txt></span><span><FindMatlab.cmake></span><span><ItkTestSimpleImFilter.cpp></span><span><MatlabMakeMacros.cmake></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>