<div dir="ltr"><div><div>Thanks again for your comments Matt! As you see, I already 'graft' :)<br><br>Based on your comments, I modified my code which got me started. Then using debugger further, I figured out I'd better implementing also VerifyInputInformation() and GenerateInputRequestedRegion(). In outcome, I now do have a working copy. So simple I'll just share it here. Not sure what happens when region-index is nonzero but for time being its ok.<br>
<br></div>Best,<br></div>-Vaaksiainen<br><br>***<br>template < class TInputImage, class TOutputImage ><br>class ResizeImageFilter : <br>public itk::ImageToImageFilter<TInputImage, TOutputImage><br>{<br>public:<br>
    typedef ResizeImageFilter Self;<br>    typedef itk::ImageToImageFilter<TInputImage,TOutputImage>    Superclass;<br>    typedef itk::SmartPointer<Self>    Pointer;<br>    typedef typename TInputImage::SpacingType SpacingType;<br>
    typedef typename TOutputImage::SizeType SizeType;<br>    <br>    itkNewMacro( Self );<br>    itkTypeMacro( ResizeImageFilter, itk::ImageToImageFilter );<br>    itkSetMacro( Scale, SpacingType );<br>    itkSetMacro( Size, SizeType );<br>
<br>protected:<br>    ResizeImageFilter()<br>    {<br>        m_Size.Fill( 0 );<br>        m_Scale.Fill( 1 );<br>    }<br>    ~ResizeImageFilter(){}<br>    void VerifyInputInformation() {}<br>    void GenerateData();<br>    void GenerateOutputInformation();<br>
    void GenerateInputRequestedRegion();<br><br>private:<br>    ResizeImageFilter & operator=(const ResizeImageFilter &rhs);<br>    ResizeImageFilter( const ResizeImageFilter &rhs);<br><br>    SpacingType m_Scale;<br>
    SizeType m_Size;<br>    SpacingType m_SpacingActual;<br>    SizeType m_SizeActual;<br>};<br>template < class TInputImage, class TOutputImage ><br>void ResizeImageFilter<TInputImage,TOutputImage><br>::GenerateData()<br>
{<br>    typedef itk::ResampleImageFilter<TInputImage,TOutputImage,float>    ResamplerType;<br>    ResamplerType::Pointer resampler = ResamplerType::New();<br>    resampler->SetOutputSpacing( m_SpacingActual );<br>
    resampler->SetSize( m_SizeActual );<br>    resampler->SetInput( this->GetInput() );<br>    resampler->GraftOutput( this->GetOutput() );<br>    resampler->Update();<br>    this->GraftOutput( resampler->GetOutput() );<br>
}<br>template < class TInputImage, class TOutputImage ><br>void ResizeImageFilter<TInputImage,TOutputImage><br>::GenerateInputRequestedRegion()<br>{<br>    this->itk::ProcessObject::GenerateInputRequestedRegion();<br>
}<br>template < class TInputImage, class TOutputImage ><br>void ResizeImageFilter<TInputImage,TOutputImage><br>::GenerateOutputInformation()<br>{<br>    const TInputImage * p = this->GetInput();<br>    if( p )<br>
    {<br>        const unsigned int N = TInputImage::ImageDimension;<br>        double decimation[N];<br>        m_SizeActual = p->GetRequestedRegion().GetSize();<br>        m_SpacingActual = p->GetSpacing();<br><br>
        for ( unsigned int n = 0; n < N; ++n )<br>        {<br>            if ( m_Size[n] == 0 ) <br>                decimation[n] = m_Scale[n];<br>            else<br>                decimation[n] = (double)m_Size[n]/(double)m_SizeActual[n];<br>
        }<br>        for ( unsigned int n = 0; n < N; ++n )<br>        {<br>            m_SpacingActual[n] /= decimation[n];<br>            m_SizeActual[n] = (unsigned int)( (double)m_SizeActual[n] * decimation[n] );<br>
            if ( m_SpacingActual[n] <= 0.0 || m_SizeActual[n] == 0 )<br>                itkExceptionMacro("spacing[n] <= 0 || size[n] == 0" );<br>        }<br>        TOutputImage * pOut = this->GetOutput();<br>
        if ( pOut )<br>        {<br>            pOut->CopyInformation( p );<br>            pOut->SetSpacing( m_SpacingActual );<br>            typename TOutputImage::RegionType region = pOut->GetRequestedRegion();<br>
            region.SetSize( m_SizeActual );<br>            pOut->SetLargestPossibleRegion( region );<br>            pOut->SetSpacing( m_SpacingActual );<br>        }<br>    }<br>}<br>***<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2013/10/16 Matt McCormick <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Vaaksiainen,<br>
<br>
The filter should implement a GenerateOutputInformation() [1] method<br>
that does the size calculation there and assigns it to the output<br>
ImageRegion's.<br>
<br>
Hope this helps,<br>
Matt<br>
<br>
[1] <a href="http://www.itk.org/Doxygen/html/classitk_1_1ProcessObject.html#abe61fb6b7de8c443e7af1561bd722736" target="_blank">http://www.itk.org/Doxygen/html/classitk_1_1ProcessObject.html#abe61fb6b7de8c443e7af1561bd722736</a><br>

<div><div class="h5"><br>
On Wed, Oct 16, 2013 at 2:42 PM, Vaaksiainen <<a href="mailto:vaaksiainen@gmail.com">vaaksiainen@gmail.com</a>> wrote:<br>
> Thanks for your quick reply, really appreciate.<br>
><br>
> I could well be using itk::ScaleTransform but I use simply resampling over<br>
> hand written spacing. I think my problem is in fact in pipelining:<br>
><br>
> void ResampleImageFilterEx<TInputImage,TOutputImage>::GenerateData()<br>
> {<br>
>     //....<br>
>     typename TInputImage::RegionType roi =<br>
> this->GetOutput()->GetRequestedRegion();<br>
>     typename TInputImage::SpacingType spacing =<br>
> this->GetInput()->GetSpacing();<br>
>     typename TInputImage::SizeType size = roi.GetSize();<br>
><br>
>     for ( unsigned int i = 0; i < TInputImage::ImageDimension; ++i)<br>
>     {<br>
>         spacing[i] /= m_Decimation;<br>
>         size[i] = (unsigned int)( (double)size[i] * m_Decimation );<br>
>     }<br>
>     itk::ResampleImageFilter<TInputImage,TOutputImage>::Pointer resampler =<br>
>         itk::ResampleImageFilter<TInputImage,TOutputImage>::New();<br>
><br>
>     resampler->SetOutputSpacing( inputSpacing );<br>
>     resampler->SetSize( inputSize );<br>
>     resampler->SetInput( this->GetInput() );<br>
><br>
>     resampler->GraftOutput( this->GetOutput() );<br>
>     resampler->Update();<br>
>     resampler->GraftOutput( pyrup->GetOutput() );<br>
> }<br>
><br>
> but if m_Decimation (or scale parameter) is given as parameter and input yet<br>
> unknown, I can't get regions propagating correctly. Because eventually I<br>
> want to call Update only for the tail filter.<br>
><br>
> Best,<br>
> -Vaaksiainen<br>
><br>
><br>
><br>
> 2013/10/16 Mike Chinander <<a href="mailto:chinander@gmail.com">chinander@gmail.com</a>><br>
>><br>
>> Check out the following example:<br>
>> <a href="http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/ScaleTransform" target="_blank">http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/ScaleTransform</a><br>
>><br>
>><br>
>> On Wed, Oct 16, 2013 at 9:10 AM, Vaaksiainen <<a href="mailto:vaaksiainen@gmail.com">vaaksiainen@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hi folks,<br>
>>><br>
>>> itk::ResampleImageFilter requires size being set before Update() so far<br>
>>> that I've understood it.<br>
>>><br>
>>> That being said, I'd wish to implement resize image filter (derivative<br>
>>> for before mentioned) which samples the image based on scaling parameter<br>
>>> relative to its input size e.g.<br>
>>><br>
>>> newWidth = scaling * oldWidth<br>
>>><br>
>>> which I figure out at GenerateData() and yet, I'd wish to be able to put<br>
>>> this filter in the pipeline not knowing the size of the input image, e.g.<br>
>>><br>
>>> Reader -> Filter#1 -> ResampleImageFilterEx -> Filter#2 -> Writer<br>
>>><br>
>>> How PropagateRequestedRegion() works and how its implemented in<br>
>>> itk::ResampleImageFilter I'm not sure if I can do this at all.<br>
>>><br>
>>> Please, any advice?<br>
>>><br>
>>> Best,<br>
>>> -Vaaksiainen<br>
>>><br>
>>><br>
>>><br>
>>><br>
>>><br>
>>> _____________________________________<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>
>><br>
>><br>
>> _____________________________________<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>
><br>
><br>
> _____________________________________<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>
</div></div>> _______________________________________________<br>
> Community mailing list<br>
> <a href="mailto:Community@itk.org">Community@itk.org</a><br>
> <a href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
><br>
</blockquote></div><br></div>