[Insight-users] Question on itk::ResampleImageFilter for up and downsampling images
Lodron, Gerald
Gerald.Lodron at joanneum.at
Thu Dec 3 09:49:10 EST 2009
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
More information about the Insight-users
mailing list