[Insight-users] Boundary problem when resampling?

stan stan.oubel at gmail.com
Fri Nov 13 10:13:37 EST 2009


Dear all,

I'm using the ITK resampling filter to upscale 3D images 
(BSplineInterpolateImageFunction).

I encountered two problems with this filter:

- there is a misregistration between high-resolution images and 
resampled low-resolution images. To correct that, I modified the origin 
( origin = origin - spacing/2). Now images are well registered,

- but now, there is a problem at image boundaries. All voxels close to 
the boundary (less than spacing/2 in all directions) are set to zero. 
This is incorrect since the size of the low-resolution have been setup 
to be exactly a multiple of the high-resolution image size.

Here a screenshot and some code I use.

Thank you

stan



  typedef short      PixelType;
  const   unsigned int        Dimension = 3;
  typedef itk::Image< PixelType, Dimension >    ImageType;
  typedef itk::ImageFileReader< ImageType >  ReaderType;
  typedef itk::ImageFileWriter< ImageType >  WriterType;
  ReaderType::Pointer reader = ReaderType::New();
  ReaderType::Pointer reader_input = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  //Reading reference image
  reader->SetFileName( reference_file  );
  reader->Update();
  ImageType::Pointer referenceImage = reader->GetOutput();

  //Reading input image
  reader_input->SetFileName( input_file  );
  reader_input->Update();
  ImageType::Pointer inputImage = reader_input->GetOutput();

  typedef itk::ResampleImageFilter<ImageType,ImageType> FilterType;
  FilterType::Pointer filter = FilterType::New();
  
  typedef itk::AffineTransform< double, Dimension >  TransformType;
  TransformType::Pointer transform = TransformType::New();
  transform -> SetIdentity();
  filter->SetTransform( transform );

  typedef itk::BSplineInterpolateImageFunction< ImageType, double, int 
 >  InterpolatorType;

  InterpolatorType::Pointer interpolator = InterpolatorType::New();
  interpolator->SetSplineOrder(interp);
  filter->SetInterpolator( interpolator );

  filter->SetDefaultPixelValue( 0 );
 
  //Initialize with reference image information
  filter->SetOutputSpacing( referenceImage->GetSpacing() );

  ImageType::SpacingType spacing = inputImage->GetSpacing();
  ImageType::PointType origin = inputImage->GetOrigin();
  origin[0] -= spacing[0]/2;
  origin[1] -= spacing[1]/2;
  origin[2] -= spacing[2]/2;

  filter->SetOutputOrigin( origin );

  filter->SetSize( referenceImage->GetLargestPossibleRegion().GetSize() );
 
  //Do the resampling
  filter->SetInput( inputImage );
  filter->Update(); 
  ImageType::Pointer outputImage = filter->GetOutput();

  //Saving the result
  writer->SetFileName( output_file );
  writer->SetInput( outputImage );
  writer->Update();

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Capture-1.png
Type: image/png
Size: 29619 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091113/c0345b81/attachment-0001.png>


More information about the Insight-users mailing list