[Insight-users] Simple resampling problem
Richard Beare
richard.beare at gmail.com
Tue Feb 16 01:21:47 EST 2010
Hi,
I'm using an obviously buggy resampling procedure to upsample a small
image that has been extracted from a larger one, and hence has non
zero origin information. My result is blank, so I'm missing a setting
somewhere, but don't have a clue as to what. Can anyone spot the
problem?
template <class RawIm>
typename RawIm::Pointer upsampleIm(typename RawIm::Pointer input,
typename RawIm::SpacingType NewSpacing, int interp=1)
{
const int dim = RawIm::ImageDimension;
typedef typename RawIm::PixelType PixelType;
typedef typename itk::ResampleImageFilter<RawIm, RawIm > ResampleFilterType;
typedef typename itk::IdentityTransform< double, dim > TransformType;
typename ResampleFilterType::Pointer resampler = ResampleFilterType::New();
input->Update();
typename TransformType::Pointer transform = TransformType::New();
transform->SetIdentity();
resampler->SetTransform( transform );
typedef typename itk::LinearInterpolateImageFunction<RawIm, double >
LInterpolatorType;
typedef typename itk::NearestNeighborInterpolateImageFunction<RawIm,
double > NNInterpolatorType;
typename ResampleFilterType::InterpolatorPointerType interpolator;
switch (interp)
{
case 0:
interpolator = NNInterpolatorType::New();
break;
case 1:
interpolator = LInterpolatorType::New();
break;
default:
std::cout << "Unsupported interpolator" << std::endl;
}
resampler->SetInterpolator( interpolator );
resampler->SetDefaultPixelValue( 0 );
const typename RawIm::SpacingType& inputSpacing = input->GetSpacing();
typename RawIm::SpacingType spacing;
typename RawIm::SizeType inputSize =
input->GetLargestPossibleRegion().GetSize();
typename RawIm::SizeType size;
typedef typename RawIm::SizeType::SizeValueType SizeValueType;
for (int i = 0; i < dim; i++)
{
float factor = inputSpacing[i]/NewSpacing[i];
size[i] = static_cast< SizeValueType >( inputSize[i] * factor );
}
std::cout << inputSpacing << NewSpacing << std::endl;
std::cout << inputSize << size << input->GetOrigin() << std::endl;
resampler->SetSize( size );
resampler->SetOutputSpacing( NewSpacing );
resampler->SetOutputOrigin( input->GetOrigin() );
resampler->SetOutputDirection(input->GetDirection());
resampler->SetInput(input);
typename RawIm::Pointer result = resampler->GetOutput();
result->Update();
result->DisconnectPipeline();
return(result);
}
//////////////////////////////////////////////////
More information about the Insight-users
mailing list