[Insight-users] Image Resampling Issue

Vikren Sarkar vikmonster at hotmail.com
Fri Sep 5 11:21:43 EDT 2008


Good morning,
 
I am trying to resample contours and am running into a bit of a problem. The method I am using is as follows: I create a matrix of zeros which is as big as the image set I am looking at. If a contour is present on a particular voxel, I set that voxel's value to 1000. I then use the code below to resample the matrix. The first case I tried was to scale all axial images by 1/2 (keeping offsets constant). When I use the NearestNeighborInterpolateImageFunction, I get the results I expect, with the occasional breaks in the contour. When I switch to the LinearInterpolateImageFunction, my instincts tell me I should get the same contour as before, except with the value of 500 instead of 1000. However, I get the exact same results as with the nearest neighbor method. Same for the BSplineInterpolateImageFunction, which incidentally does take much longer to run. I woul dvery much appreciate it if someone could point me to the mistake I am making, either with the code or with my thought process... Thank you for your help. 
Vik
 
Code: 
 
#include "itkImage.h"#include "itkImageFileReader.h"#include "itkImageFileWriter.h"#include "itkResampleImageFilter.h"#include "itkLinearInterpolateImageFunction.h"
 
int main( int argc, char * argv[] ){  if( argc < 3 )    {    std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << "  Resampleto.mhd currentcontour.mhd " << std::endl;     return EXIT_FAILURE;    }
 
  const     unsigned int   Dimension = 3;  typedef   unsigned short   PixelType;
 
  typedef itk::Image< PixelType,  Dimension >   FixedImageType;  typedef itk::Image< PixelType,  Dimension >   MovingImageType;  typedef itk::Image< PixelType,  Dimension >   OutputImageType;
  typedef itk::ImageFileReader< FixedImageType  >  ReaderType;  typedef itk::ImageFileReader< MovingImageType  >  ReaderType;  typedef itk::ImageFileWriter< OutputImageType >  WriterType;
 
  ReaderType::Pointer fixedreader = ReaderType::New();  ReaderType::Pointer movingreader = ReaderType::New();  WriterType::Pointer writer = WriterType::New();
  fixedreader->SetFileName( argv[1] );  movingreader->SetFileName( argv[2] );  writer->SetFileName( "Resampledcontours.mhd" );
  fixedreader->Update();
 
  typedef itk::ResampleImageFilter<                  MovingImageType, OutputImageType >  FilterType;  FilterType::Pointer filter = FilterType::New();    typedef itk::IdentityTransform< double, Dimension > TransformType;  TransformType::Pointer transform = TransformType::New();  transform->SetIdentity();  filter->SetTransform( transform );
 
  typedef itk::LinearInterpolateImageFunction<                        MovingImageType, double >  InterpolatorType;  InterpolatorType::Pointer interpolator = InterpolatorType::New();  filter->SetInterpolator( interpolator );
  filter->SetDefaultPixelValue( 0 );
 
  double spacing[ Dimension ];
  spacing[0] = fixedreader->GetOutput()->GetSpacing()[0];  spacing[1] = fixedreader->GetOutput()->GetSpacing()[1];  spacing[2] = fixedreader->GetOutput()->GetSpacing()[2];  filter->SetOutputSpacing( spacing );
  
  double origin[ Dimension ];  origin[0] = fixedreader->GetOutput()->GetOrigin()[0];  origin[1] = fixedreader->GetOutput()->GetOrigin()[1];  origin[2] = fixedreader->GetOutput()->GetOrigin()[2];  filter->SetOutputOrigin( origin );
 
  filter->SetSize( fixedreader->GetOutput()->GetLargestPossibleRegion().GetSize() );
 
  filter->SetInput( movingreader->GetOutput() );    writer->SetInput( filter->GetOutput() );   try     {    writer->Update();    }  catch( itk::ExceptionObject & excep )    {    std::cerr << "Exception catched !" << std::endl;    std::cerr << excep << std::endl;    }
 return EXIT_SUCCESS;}
 
_________________________________________________________________
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080905/e45fe6ae/attachment-0001.htm>


More information about the Insight-users mailing list