[Insight-users] ResampleImageFilter : blank result from upsampling x2

Vaaksiainen vaaksiainen at gmail.com
Thu Sep 26 06:12:30 EDT 2013


Thanks Matt,

Your observations were indeed helpful. Grafting the output at all
associated filters (especially the one in between resamplers) solved my
issue.

Talking about grafting and pipelines, I have two additional questions:

(1) Is it ok to use grafting if minipipeline filters are constructed at
GenerateData() -scope (vs. class members as suggested in the (old) manual).
It seems to be.

(2) Are both codes below valid alternatives? Latter is not used as is
(naturally), but in analogue after some processing of 'in.Get()' values.

Thanks in advance,
-Vaaksiainen

void ::GenerateDataA() // AwesomeImageToImageFilter<TImg,TImg>
{
    itk::MyPrivateImageToImageFilter<TImg,TImg>        FilterType;
    FilterType::Pointer filter = FilterType::New();
    filter->SetInput( this->GetInput() );
    filter->GraftOutput( this->GetOutput() );
    filter->Update();
    this->GraftOutput( filter->GetOutput() );
}

void ::GenerateDataB() // AwesomeImageToImageFilter<TImg,TImg>
{
    itk::MyPrivateImageToImageFilter<TImg,TImg>        FilterType;
    FilterType::Pointer filter = FilterType::New();
    filter->SetInput( this->GetInput() );
    filter->Update();

    typename TImg::RegionType region =
this->GetOutput()->GetRequestedRegion();
    this->GetOutput()->SetBufferedRegion( region );
    this->Allocate();

    itk::ImageRegionIterator<TImg> out( this->GetOutput(), region );
    itk::ImageRegionConstIterator<TImg> in( filter->GetOutput(), region );

    for (; !out.IsAtEnd(); ++out, ++in )
    {
        out.Set( in.Get() );
    }
}




2013/9/25 Matt McCormick <matt.mccormick at kitware.com>

> Hi Vaaksianinen,
>
> Two observations may be useful.
>
>   - The resampler is being told to use the reference image but the
> parameters of the output image are also being set at the same time.
> One or the other should be used -- in this case the reference image
> should not be used.
>   - When writing a composite filter, it is important to use the Graft
> methods. -- see the Software Guide on writing a composite filter.
>
> Hope this helps,
> Matt
>
> On Wed, Sep 25, 2013 at 8:02 AM, Vaaksiainen <vaaksiainen at gmail.com>
> wrote:
> > Hello yall
> >
> > I'm suffering with ResampleImageFilter. In particular, upsampling an
> image
> > produces all zero image (or whatever defaultpixelvalue happens to be)
> and I
> > just can't figure out why?
> >
> > Basically, I'm writing a composite filter, which downsamples the image
> for
> > some internal purpose as follows (purposely using linear interpolation,
> not
> > Gaussian):
> >
> > Some times I explicitly added IdentityTransform and
> > LinearInterpolateImageFunction, but as far as I know, they are defaults
> so I
> > left them out. If I comment out pyramid up (preprocessor if statement),
> then
> > I get the actual downsampled image from my filter as output. So the only
> > problem is upsampling.
> >
> > I have examined the output from 'filter' and it has spacing as expected
> > (twice the size of original input), origin at zero, directions following
> > cartesian axes and image size half the original. So nothing there... As
> you
> > see, have tried have tried multiple combinations for pyrup parameters,
> none
> > seems working.
> >
> > Help appreciated.
> >
> > Best
> > -Vaaksiainen
> >
> > BTW, using ITK 4.4.1, Visual Studio 9, Windows 7 x64.
> >
> > ******
> >
> > typedef itk::ResampleImageFilter<
> > TImage, TImage, float >        ResamplerType;
> > typedef MyOwnImageToImageFilter<TImage,TImage>
> > MyOwnImageToImageFilter;
> >
> > typename TImage::SpacingType spacing = this->GetInput()->GetSpacing();
> > typename TImage::SizeType size =
> > this->GetOutput()->GetRequestedRegion().GetSize();
> >
> > // e.g. m_Decimation = .5
> > for ( unsigned int i = 0; i < TImage::ImageDimension; ++i)
> > {
> >     spacing[i] /= m_Decimation;
> >     size[i] = (unsigned int)( (double)size[i] * m_Decimation );
> > }
> >
> > ResamplerType::Pointer pyrdown = ResamplerType::New();
> > pyrdown->SetOutputSpacing( spacing );
> > pyrdown->SetSize( size );
> > pyrdown->SetInput( this->GetInput() );
> >
> > MyOwnImageToImageFilter::Pointer filter = MyOwnImageToImageFilter::New();
> > // set filter parameters
> > filter->SetInput( pyrdown->GetOutput() );
> >
> > #if 1
> > ResamplerType::Pointer pyrup = ResamplerType::New();
> > //pyrup->SetOutputSpacing( this->GetInput()->GetSpacing() );
> > pyrup->SetUseReferenceImage( 1 );
> > pyrup->SetReferenceImage( this->GetInput() );
> > //pyrup->SetOutputStartIndex( roi.GetIndex() );
> > //pyrup->SetSize( this->GetOutput()->GetRequestedRegion().GetSize() );
> > pyrup->SetInput( filter->GetOutput() );
> > pyrup->SetDefaultPixelValue( 14.0f );
> > #else
> > MyOwnImageToImageFilter::Pointer pyrup = filter;
> > #endif
> >
> > pyrup->Update();
> >
> > this->SetNthOutput( 0, pyrup->GetOutput() );
> >
> > _____________________________________
> > 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/20130926/71a28e66/attachment.htm>


More information about the Insight-users mailing list