[Insight-users] Simple resampling problem

Luis Ibanez luis.ibanez at kitware.com
Tue Feb 16 10:04:06 EST 2010


Hi Richard,

If you set

          NewSpacing = inputSpacing,

Do you get as output an image
that looks like the input image ?


What are the values of

* inputSpacing ?
* inputSize ?
* inputOrigin ?
* inputDirection ?


Please let us know,


    Thanks


         Luis


------------------------------------------
On Tue, Feb 16, 2010 at 1:21 AM, 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
>


More information about the Insight-users mailing list