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

Vaaksiainen vaaksiainen at gmail.com
Thu Sep 26 08:32:38 EDT 2013


Many thanks for your comments! Especially the bonus :-)

Regarding the manual page:

ItkSoftwareGuide-2.4.0 : page 768 says "4. The default constructor should
build the pipeline by creating the stages and connect them together, along
with any default parameter settings, as appropriate."

My reasons not to do this were exactly ones you mentioned. And to not to
add all (not necessary needed) subfilter configurations in class members.

Best regards,
-Vaaksiainen



2013/9/26 Bradley Lowekamp <blowekamp at mail.nih.gov>

> Vaaksianen,
>
>  Comments below:
>
> On Sep 26, 2013, at 6:12 AM, Vaaksiainen <vaaksiainen at gmail.com> wrote:
>
> 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.
>
>
> I didn't realize that was in the manual. What page?
>
> I have updated a number of filters to allocate the mini-pipeline internal
> filters inside the GenerateData method. This was done because the class
> scoped internal filters many times hold on to memory between executions,
> and it is just to error prone to have to manually release their data
> outputs.  For the class scoped internal filters, generally the extra memory
> usage far out ways the cost of reallocating the internal filters each
> update ( if there is even more than one ).
>
>
>
> (2) Are both codes below valid alternatives? Latter is not used as is
> (naturally), but in analogue after some processing of 'in.Get()' values.
>
>
>
>
> The first one is preferred, while the second one can produce correct
> results it's slower and take more memory.
>
>
> 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() );
>
>
> You should set the filter's output's requested region here.
>
>     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 );
>
>
> I'd use ImageAlgorithm::Copy instead of the for loop, it can be up to 50X
> faster:
>
> http://www.itk.org/Doxygen/html/structitk_1_1ImageAlgorithm.html#a5ec5bcac992cb3b1302840636530ba20
>
>
>     for (; !out.IsAtEnd(); ++out, ++in )
>     {
>         out.Set( in.Get() );
>     }
> }
>
>
> And some detail bonus info!
>
> With the above examples, the execution of the internal pipeline escapes
> the filter and causes prior external filters to update the output info and
> may cause additional executions which can some times be a problem or just
> cause extra processing.
>
> The mini-pipeline can be isolated from this by using a graft input. Here
> is an example of how it can be done:
>
> https://github.com/Kitware/ITK/blob/master/Modules/Filtering/Smoothing/include/itkDiscreteGaussianImageFilter.hxx#L128
>
> While mini-pipeline are the easiest to write and get something working,
> they are very hard to get everything working correctly!
>
> Brad
>
>
>
>
>
>
> 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
>> >
>>
>
> _____________________________________
> 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/64ea89e3/attachment.htm>


More information about the Insight-users mailing list