[Insight-users] Question on itk::ResampleImageFilter for up and downsampling images

Bill Lorensen bill.lorensen at gmail.com
Thu Dec 3 10:34:57 EST 2009


What version of itk are you using? Prior to itk 3.16 there was an
issue with the location of sample points. IN 3.16 we changed the
default for ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY to be ON.
This made itk consistent with the behavior described in the software
guide. It also corrected the 1/2 pixel offset you are seeing when
down/up sampling.

If you are using 3.14, you can set
ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY ON when you run cmake.

Bill

On Thu, Dec 3, 2009 at 9:49 AM, Lodron, Gerald
<Gerald.Lodron at joanneum.at> wrote:
>
>
> Hello,
>
> I want to write a code to reduce/increase the resolution of an image and i am using the itk::ResampleImageFilter. The code works fine but there is one small problem: When i compare the original and the resampled image with a checkerboard i see that the images are not registered any more (so there must be a problem with the origin). How should i set the origin? Here my code:
>
> Input:
>
> Int *iDownsampleFactor;                                 // = e.g. {2,0.5,4};
> Itk::OrientedImage<PixelType ,3>::Pointer image;
>
> Code:
>
> Typedef itk::ResampleImageFilter<InputImageType, OutputImageType, InterpolationPrecisionType> ResampleType;
>
> ResampleType::Pointer  resampler = ResampleType::New();
>
> OutputImageType::SpacingType                    Spacing;
> OutputImageType::PointType                      Origin;
> OutputImageType::DirectionType          Direction = image->GetDirection();
> OutputImageType::SizeType                       Size;
> OutputImageType::RegionType::IndexType  Index = image->getLargestPossibleRegion().GetIndex();
>
> For (int i=0; i<3; i++)
> {
>        Spacing[i] = image->GetSpacing()[i] * iDownsampleFactor[i] ;
>        Origin[i] = image->GetOrigin()[i];//????????????????????
>        Size[i] = image->GetLargestPossibleRegion().GetSize()[i]/iDownsampleFactor[i] ;
> }
>
> Resampler->SetInput(image);
> resampler->SetOutputSpacing( Spacing );
> resampler->SetOutputOrigin(  Origin  );
> resampler->SetOutputDirection(  Direction  );
> resampler->SetSize( Size );
> resampler->SetOutputStartIndex(  Index );
>
> Output = resampler->GetOutput();        //Wrong alignment/registration to input
>
> Best regards
>
>
> _____________________________________
> 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.html
>
> 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