[Insight-users] Problem grafting a C++ array as an ImageToImageFilter output
Ramón Casero Cañas
rcasero at gmail.com
Sun May 26 12:06:29 EDT 2013
Hi Matt,
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. :/
Best regards,
Ramon.
On 26 May 2013 02:33, Matt McCormick <matt.mccormick at kitware.com> wrote:
> Hi Ramon,
>
> The approach of using SetImportPointer on the Output is not guaranteed
> to work. The assumption is that the ImageToImageFilter is creating
> its Output. It is more reliable to copy the produced Output to the
> buffer.
>
> HTH,
> Matt
>
> On Fri, 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/
> >
> > _____________________________________
> > 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
> >
>
--
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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130526/265e8c23/attachment.htm>
More information about the Insight-users
mailing list