[Insight-users] Problem grafting a C++ array as an ImageToImageFilter output

Bradley Lowekamp blowekamp at mail.nih.gov
Thu May 30 08:41:27 EDT 2013


Hello,

There a many options to choose from to minimize memory. Some filter run in-place, and re-use the input buffer on the output.

Can you use the image buffer from ITK and import it into matlab? Does matlab not have the ability to import a buffer?

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.

Brad

On May 24, 2013, at 7:16 PM, Ramón Casero Cañas <rcasero at gmail.com> wrote:

> Hi all,
> 
> 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.
> 
> 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.
> 
> 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).
> 
> Save everything to directory test, and then build the example from the shell
> 
> cd test
> mkdir bin
> cd bin
> cmake ..
> make install
> 
> To run the example from Matlab,
> 
> cd test
> % create a test binary square with a little hole
> im = zeros(15, 15, 'uint8');
> im(3:13, 3:13) = 1;
> im(7:8, 7) = 0;
> im2 = itk_test(im);
> 
> 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
> 
> Filter result, reading from the filter
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> Filter result, reading from the Matlab output array
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 
> 
> But this approach works for other filters. If we choose the Median filter instead: in ItkTestSimpleImFilter.cpp, ucomment
> 
>   // typedef itk::MedianImageFilter<ImageType, ImageType>
>   //   FilterType;
> 
> and comment out
> 
>   typedef itk::VotingBinaryIterativeHoleFillingImageFilter<ImageType>
>     FilterType;
> 
> [...]
> 
>   // filter parameters only for the VotingBinaryIterativeHoleFillingImageFilter
>   filter->SetMaximumNumberOfIterations(4);
>   filter->SetBackgroundValue(0);
>   filter->SetForegroundValue(1);
>   filter->SetMajorityThreshold(2);
> 
> then we can see that the array is actually being used as the filter's output
> 
> >> im2 = itk_test(im);
> Filter result, reading from the filter
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> Filter result, reading from the Matlab output array
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
> 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 
> I have been looking at itkVotingBinaryIterativeHoleFillingImageFilter.hxx, and I was wondering whether the problem is in VotingBinaryIterativeHoleFillingImageFilter< TInputImage >
> ::GenerateData().
> 
> The filter works iteratively, doing
> 
>   while ( m_CurrentNumberOfIterations < m_MaximumNumberOfIterations )
>     {
>     filter->SetInput(input);
>     filter->Update();
> 
>     m_CurrentNumberOfIterations++;
>     progress.CompletedPixel();   // not really a pixel but an iteration
>     this->InvokeEvent( IterationEvent() );
> 
>     const unsigned int numberOfPixelsChangedInThisIteration =
>       filter->GetNumberOfPixelsChanged();
>     m_NumberOfPixelsChanged += numberOfPixelsChangedInThisIteration;
> 
>     output = filter->GetOutput();
>     output->DisconnectPipeline();
>     input = output;
>     if ( numberOfPixelsChangedInThisIteration == 0 )
>       {
>       break;
>       }
>     }
>   this->GraftOutput(output);
> 
> 
> 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.
> 
> [1] https://groups.google.com/forum/?fromgroups#!topic/gerardus-users/pLH0iR0H74o
> 
> Best regards,
> 
> Ramon.
> 
> 
> 
> 
> -- 
> Dr. Ramón Casero Cañas
> 
> Oxford e-Research Centre (OeRC)
> University of Oxford
> 7 Keble Rd
> Oxford OX1 3QG
> 
> tlf     +44 (0) 1865 610739
> web     http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas
> photos  http://www.flickr.com/photos/rcasero/
> <CMakeLists.txt><FindMatlab.cmake><ItkTestSimpleImFilter.cpp><MatlabMakeMacros.cmake>_____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130530/011e16de/attachment.htm>


More information about the Insight-users mailing list