[Insight-users] Simple resampling problem
Darren Weber
darren.weber.lists at gmail.com
Thu Feb 18 18:59:13 EST 2010
Maybe change this
resampler->SetInput(input);
to this
resampler->SetInput( input->GetOutput() );
On Mon, Feb 15, 2010 at 10:21 PM, Richard Beare <richard.beare at gmail.com>wrote:
> 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);
> }
>
> //////////////////////////////////////////////////
> _____________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100218/96c06cdf/attachment-0001.htm>
More information about the Insight-users
mailing list