<div dir="ltr">Hi Matt,<div><br></div><div style>Many thanks for your reply. It's a pity. When using SetImportPointer on the Output works, it saves having to duplicate the output in memory, which for an image can be large. :/</div>
<div style><br></div><div style>Best regards,</div><div style><br></div><div style>Ramon.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 26 May 2013 02:33, Matt McCormick <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Ramon,<br>
<br>
The approach of using SetImportPointer on the Output is not guaranteed<br>
to work. The assumption is that the ImageToImageFilter is creating<br>
its Output. It is more reliable to copy the produced Output to the<br>
buffer.<br>
<br>
HTH,<br>
Matt<br>
<div><div class="h5"><br>
On Fri, May 24, 2013 at 7:16 PM, Ramón Casero Cañas <<a href="mailto:rcasero@gmail.com">rcasero@gmail.com</a>> wrote:<br>
> Hi all,<br>
><br>
> I think there may be some problem with some of the itk::ImageToImageFilter<br>
> when one tries to graft a C++ array to be used as the filter's output, or at<br>
> least with the way I do it.<br>
><br>
> This was kindly reported by Peter Thalmann in [1], and I'm trying to help<br>
> him. This is a problem that I had also noticed with a couple of other<br>
> filters.<br>
><br>
> I have attached a minimal example of a C++ MEX file that creates a function<br>
> that can be run from Matlab, with the CMake files to compile it. (I have<br>
> tried this with ITK 4.3.1).<br>
><br>
> Save everything to directory test, and then build the example from the shell<br>
><br>
> cd test<br>
> mkdir bin<br>
> cd bin<br>
> cmake ..<br>
> make install<br>
><br>
> To run the example from Matlab,<br>
><br>
> cd test<br>
> % create a test binary square with a little hole<br>
> im = zeros(15, 15, 'uint8');<br>
> im(3:13, 3:13) = 1;<br>
> im(7:8, 7) = 0;<br>
> im2 = itk_test(im);<br>
><br>
> This runs filter itk::VotingBinaryIterativeHoleFillingImageFilter on the<br>
> image. The program outputs to the Matlab shell both the content of<br>
> filter->GetOutput(), and the content of the Matlab output array. As we can<br>
> see, the output is not being saved to the array<br>
><br>
> Filter result, reading from the filter<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> Filter result, reading from the Matlab output array<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
><br>
><br>
> But this approach works for other filters. If we choose the Median filter<br>
> instead: in ItkTestSimpleImFilter.cpp, ucomment<br>
><br>
> // typedef itk::MedianImageFilter<ImageType, ImageType><br>
> // FilterType;<br>
><br>
> and comment out<br>
><br>
> typedef itk::VotingBinaryIterativeHoleFillingImageFilter<ImageType><br>
> FilterType;<br>
><br>
> [...]<br>
><br>
> // filter parameters only for the<br>
> VotingBinaryIterativeHoleFillingImageFilter<br>
> filter->SetMaximumNumberOfIterations(4);<br>
> filter->SetBackgroundValue(0);<br>
> filter->SetForegroundValue(1);<br>
> filter->SetMajorityThreshold(2);<br>
><br>
> then we can see that the array is actually being used as the filter's output<br>
><br>
>>> im2 = itk_test(im);<br>
> Filter result, reading from the filter<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> Filter result, reading from the Matlab output array<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0<br>
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
><br>
> I have been looking at itkVotingBinaryIterativeHoleFillingImageFilter.hxx,<br>
> and I was wondering whether the problem is in<br>
> VotingBinaryIterativeHoleFillingImageFilter< TInputImage ><br>
> ::GenerateData().<br>
><br>
> The filter works iteratively, doing<br>
><br>
> while ( m_CurrentNumberOfIterations < m_MaximumNumberOfIterations )<br>
> {<br>
> filter->SetInput(input);<br>
> filter->Update();<br>
><br>
> m_CurrentNumberOfIterations++;<br>
> progress.CompletedPixel(); // not really a pixel but an iteration<br>
> this->InvokeEvent( IterationEvent() );<br>
><br>
> const unsigned int numberOfPixelsChangedInThisIteration =<br>
> filter->GetNumberOfPixelsChanged();<br>
> m_NumberOfPixelsChanged += numberOfPixelsChangedInThisIteration;<br>
><br>
> output = filter->GetOutput();<br>
> output->DisconnectPipeline();<br>
> input = output;<br>
> if ( numberOfPixelsChangedInThisIteration == 0 )<br>
> {<br>
> break;<br>
> }<br>
> }<br>
> this->GraftOutput(output);<br>
><br>
><br>
> Here, output gets a DisconnectPipeline(). I have tried commenting that like<br>
> out, rebuilding and reinstalling ITK, but it doesn't seem to make a<br>
> difference.<br>
><br>
> [1]<br>
> <a href="https://groups.google.com/forum/?fromgroups#!topic/gerardus-users/pLH0iR0H74o" target="_blank">https://groups.google.com/forum/?fromgroups#!topic/gerardus-users/pLH0iR0H74o</a><br>
><br>
> Best regards,<br>
><br>
> Ramon.<br>
><br>
><br>
><br>
><br>
> --<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><br>
><br>
</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>
><br>
</blockquote></div><br><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>