[Insight-users] Resample filter

Josiane NJIWA njiwa at biomed.ee.ethz.ch
Wed Nov 19 07:12:35 EST 2008


Dear all,

I would like to rescale or interpolate an image for registration. For 
this aim, i used resample filter where i changes the spacing coordinate. 
The obtained image is completed define in the image matrix. I change the 
origin parameters without success.could somebody help me? My source code 
is expressed below:


#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#include "itkAffineTransform.h"
#include "itkNearestNeighborInterpolateImageFunction.h"


int main( int argc, char * argv[] )
{
  if( argc < 4 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << "  inputImageFile  outputImageFile";
    std::cerr << "  [exampleAction={0,1,2,3,4}]" << std::endl;
    return EXIT_FAILURE;
    }

  int exampleAction = 0;
 
  if( argc >= 4 )
    {
    exampleAction = atoi( argv[3] );
    }

  const     unsigned int   Dimension = 3;
  typedef   float   InputPixelType;
  typedef   float  OutputPixelType;

  typedef itk::Image< InputPixelType,  Dimension >   InputImageType;
  typedef itk::Image< OutputPixelType, Dimension >   OutputImageType;


  typedef itk::ImageFileReader< InputImageType  >  ReaderType;
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  reader->SetFileName( argv[1] );
  writer->SetFileName( argv[2] );


  typedef itk::ResampleImageFilter<
                  InputImageType, OutputImageType >  FilterType;

  FilterType::Pointer filter = FilterType::New();
  typedef itk::AffineTransform< double, Dimension >  TransformType;
  TransformType::Pointer transform = TransformType::New();

  typedef itk::LinearInterpolateImageFunction<
                       InputImageType, double >  
InterpolatorType;//NearestNeighbor
  InterpolatorType::Pointer interpolator = InterpolatorType::New();
  filter->SetInterpolator( interpolator );
  reader->Update();
  InputImageType::Pointer fixedImage = reader->GetOutput();
  double spacing[ Dimension ];
  spacing[0] = 0.17*1.750;
  spacing[1] = 0.17*1.750;
  spacing[2] = 0.13;

  filter->SetOutputSpacing( spacing );
 
  filter->SetOutputOrigin(  fixedImage->GetOrigin() );

  InputImageType::SizeType   size;
 
  size[0] = 256;
  size[1] = 256;
  size[2] = 100;

  filter->SetSize( size );
  filter->SetInput( reader->GetOutput() );
  writer->SetInput( filter->GetOutput() );
  transform->SetIdentity();
  filter->SetTransform( transform );


 
  if( exampleAction == 0 )
    {
    writer->Update();
    }
 
 
  filter->SetOutputSpacing( Image->GetSpacing() );
 

  return EXIT_SUCCESS;


More information about the Insight-users mailing list