[Insight-users] Reuse of filter with different parameters and images

Krzysztof J. Rechowicz k.rechowicz at gmail.com
Thu Nov 8 11:34:37 EST 2012


Dear Jon,

Indeed that was the issue. We were mainly focused on updating the
pipeline as the solution.

Thank you,

Krzysztof

On Thu, Nov 8, 2012 at 2:47 AM, Jon Haitz Legarreta
<jhlegarreta at vicomtech.org> wrote:
> Dear Krzysztof,
> you are actually generating a circular loop.
>
> You may want to use the DisconnectPipeline method for the first output you
> are getting so that your data objects gets disconnected from the upstream
> pipeline. Then, plugging this input to the filter should do the trick, if
> I'm not wrong.
>
> Anyway, using two separate filters for your program is a completely
> acceptable solution.
>
> Kind regards,
> JON HAITZ
>
>
>
> On 8 November 2012 04:54, Krzysztof J. Rechowicz <k.rechowicz at gmail.com>
> wrote:
>>
>> Hello,
>>
>>
>> In the piece of code I am working on I want to reuse ResampleFilter.
>> The first use downscale the image to low resolution (which is
>> performed correctly) and then the output is used to be upscaled using
>> bicubic interpolation. After this operation, the resulting image is
>> identical as the image that was read in (the original image before
>> applying any filters) instead of being blurred. Using another instance
>> of the filter for the second part works well and produces the right
>> output. How to correctly reuse a filter (in this case ResampleFilter)?
>>
>> Thank you in advance,
>>
>> Krzysztof
>>
>> // Instantiate the transform and specify it should be the id transform.
>> TransformType::Pointer _pTransform = TransformType::New();
>>   _pTransform->SetIdentity();
>> // Instantiate the b-spline interpolator and set it as the third order
>> // for bicubic.
>> InterpolatorType::Pointer _pInterpolator = InterpolatorType::New();
>> _pInterpolator->SetSplineOrder(3);
>>
>> // Instantiate the resampler. Wire in the transform and the interpolator.
>> ResampleFilterType::Pointer _pResizeFilter = ResampleFilterType::New();
>> _pResizeFilter->SetTransform(_pTransform);
>> _pResizeFilter->SetInterpolator(_pInterpolator);
>>
>> const double vfOutputOrigin[2] = { 0.0, 0.0 };
>> _pResizeFilter->SetOutputOrigin(vfOutputOrigin);
>>
>> // Fetch original image size.
>> const ImageType::RegionType& inputRegion =
>> image->GetLargestPossibleRegion();
>> const ImageType::SizeType& vnInputSize = inputRegion.GetSize();
>> unsigned int nOldWidth = vnInputSize[0];
>> unsigned int nOldHeight = vnInputSize[1];
>>
>> unsigned int nNewWidth = vnInputSize[0]/scale;
>> unsigned int nNewHeight = vnInputSize[1]/scale;
>>
>> // Fetch original image spacing.
>> const ImageType::SpacingType& vfInputSpacing = image->GetSpacing();
>>
>> double vfOutputSpacing[2];
>> vfOutputSpacing[0] = vfInputSpacing[0] * (double) nOldWidth / (double)
>> nNewWidth;
>> vfOutputSpacing[1] = vfInputSpacing[1] * (double) nOldHeight /
>> (double) nNewHeight;
>>
>> _pResizeFilter->SetOutputSpacing(vfOutputSpacing);
>> itk::Size<2> vnOutputSize = { {nNewWidth, nNewHeight} };
>> _pResizeFilter->SetSize(vnOutputSize);
>> _pResizeFilter->SetInput(image);
>> _pResizeFilter->Update();
>> ImageType::Pointer lores = _pResizeFilter->GetOutput();
>> _pResizeFilter->UpdateLargestPossibleRegion();
>>
>>
>>                 const ImageType::RegionType& inputRegion2 =
>> lores->GetLargestPossibleRegion();
>>                 const ImageType::SizeType& vnInputSize2 =
>> inputRegion2.GetSize();
>>                 nOldWidth = vnInputSize2[0];
>>                 nOldHeight = vnInputSize2[1];
>>                 //
>>                 nNewWidth = vnInputSize2[0]*scale;
>>                 nNewHeight = vnInputSize2[1]*scale;
>>                 const ImageType::SpacingType& vfInputSpacingLow =
>> lores->GetSpacing();
>>                 vfOutputSpacing[0] = vfInputSpacingLow[0] * (double)
>> nOldWidth /
>> (double) nNewWidth;
>>                 vfOutputSpacing[1] = vfInputSpacingLow[1] * (double)
>> nOldHeight /
>> (double) nNewHeight;
>>
>>                 _pResizeFilter->SetTransform(_pTransform);
>>                 _pResizeFilter->SetInterpolator(_pInterpolator);
>>                 _pResizeFilter->SetOutputOrigin(vfOutputOrigin);
>>                 _pResizeFilter->SetOutputSpacing(vfOutputSpacing);
>>                 vnOutputSize[0] = nNewWidth;
>>                 vnOutputSize[1] = nNewHeight;
>>                 _pResizeFilter->SetSize(vnOutputSize);
>>                 _pResizeFilter->UpdateLargestPossibleRegion();
>>                 _pResizeFilter->SetInput(lores);
>>                 _pResizeFilter->Modified();
>>                 _pResizeFilter->Update();
>> _____________________________________
>> 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
>
>


More information about the Insight-users mailing list