[ITK] [ITK-users] Simple Resampling delivers empty image

Michael_A deratwu at hotmail.de
Wed Nov 5 05:40:14 EST 2014


Hello people,

i could need your help regarding resampling. I seem to forget something
small, but important, yet just cant find it...

I have 2 NIFTI Images. One has been written by an ITK resampler, the other
was written by the Softeware "VINCI".
I want to do a squared difference of the images (via ITK filter) yet they
are not in the same direction!
One has:
1 0 0
0 1 0
0 0 1

the other has:
-1 0 0
0 -1 0
0 0 1

so i want to resample the image of the one into the others direction. I flip
it via the FLIP-Filter and then
resample it. But the resampled Image is completely empty! Why?
My code is:

int main(int argc, char **argv)
{
  static const unsigned int    ImageDimension = 3;
  typedef  signed short    PixelType;

  typedef itk::Image< PixelType, ImageDimension >  ImageType;
  //
  //   Read the Fixed and Moving images.
  // 
  typedef itk::ImageFileReader< ImageType  > FixedImageReaderType;
  typedef itk::ImageFileReader< ImageType > MovingImageReaderType;

  FixedImageReaderType::Pointer  fixedImageReader  =
FixedImageReaderType::New();
  MovingImageReaderType::Pointer movingImageReader =
MovingImageReaderType::New();

  fixedImageReader->SetFileName(  argv[1] );
  movingImageReader->SetFileName( argv[2] );

  typedef itk::ImageRegistrationMethod< 
                                    ImageType, 
                                    ImageType >    RegistrationType;
  typedef itk::VersorRigid3DTransform< double > RigidTransformType;
  typedef itk:: LinearInterpolateImageFunction< 
                                    ImageType,
                                    double          >    InterpolatorType;				    
  typedef itk::ResampleImageFilter< ImageType, ImageType >   
ResampleFilterType;
  typedef itk::ImageFileWriter< ImageType >  WriterType;
  WriterType::Pointer writer = WriterType::New(); 

  writer->SetFileName( argv[3]);

  InterpolatorType::Pointer   interpolator  = InterpolatorType::New();
  RigidTransformType::Pointer transform = RigidTransformType::New();
  ResampleFilterType::Pointer resample = ResampleFilterType::New();
  
   typedef itk::FlipImageFilter< ImageType > FilterType;
   FilterType::Pointer filter = FilterType::New();

   typedef FilterType::FlipAxesArrayType FlipAxesArrayType;
   FlipAxesArrayType flipArray;

   flipArray[0] = atoi( argv[4] );

   flipArray[1] = atoi( argv[5] );
   
   flipArray[2] = atoi( argv[6] );

   filter->SetFlipAxes( flipArray );
   filter->SetInput(movingImage);
   filter->Update();
   
  resample->SetTransform( transform );
  resample->SetInterpolator(interpolator);
  resample->SetInput( filter->GetOutput() );
  resample->SetSize(   
fixedImageReader->GetOutput()->GetLargestPossibleRegion().GetSize() );
  resample->SetOutputOrigin(  fixedImageReader->GetOutput()->GetOrigin() );
  resample->SetOutputSpacing( fixedImageReader->GetOutput()->GetSpacing() );
  resample->SetOutputDirection(
fixedImageReader->GetOutput()->GetDirection() );
  resample->SetDefaultPixelValue( 0 );

      try
      {
      resample->Update();
      }
    catch( itk::ExceptionObject & err ) 
      { 
      std::cerr << "ExceptionObject caught !" << std::endl; 
      std::cerr << err << std::endl; 
      return EXIT_FAILURE;
      } 
  
  writer->SetInput(resample->GetOutput());

    std::cout << "Writing Resampled Image..." << std::endl;
    try
      {
      writer->Update();
      }
    catch( itk::ExceptionObject & err ) 
      { 
      std::cerr << "ExceptionObject caught !" << std::endl; 
      std::cerr << err << std::endl; 
      return EXIT_FAILURE;
      } 
      
 return EXIT_SUCCESS;
}


Headers are all included of course. Can somebody help me with this?
Thanks in advance,
Michael




--
View this message in context: http://itk-users.7.n7.nabble.com/Simple-Resampling-delivers-empty-image-tp34867.html
Sent from the ITK - Users mailing list archive at Nabble.com.
_____________________________________
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.php

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://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list