[Insight-users] Cartesian to polar image filter

alex Dowson alexdowson at hotmail.com
Thu Oct 20 05:26:28 EDT 2011


Hi

I am trying to do conversion of image from Cartesian to polar using itk::ResampleImageFilter but result is not proper.

I am doing polar and Cartesian vice versa conversion using code given at 
http://www.insight-journal.org/browse/publication/130

But it does not producing perfect image as output. Any one can tell me what I am doing wrong ?

Here is code of my example.

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

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


  const     unsigned int   Dimension = 2;
  typedef   unsigned char  InputPixelType;
  typedef   unsigned char  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::CartesianToPolarTransform<double,Dimension>  TransformType;
  TransformType::Pointer transform = TransformType::New();
  filter->SetTransform( transform );

  typedef itk::NearestNeighborInterpolateImageFunction< 
                       InputImageType, double >  InterpolatorType;
  InterpolatorType::Pointer interpolator = InterpolatorType::New();
  filter->SetInterpolator( interpolator );
  filter->SetDefaultPixelValue( 0 );

  double spacing[ Dimension ];
  spacing[0] = 1.0; // pixel spacing in millimeters along X
  spacing[1] = 1.0; // pixel spacing in millimeters along Y

  filter->SetOutputSpacing( spacing );

  double origin[ Dimension ];
  origin[0] = 0.0;  // X space coordinate of origin
  origin[1] = 0.0;  // Y space coordinate of origin

  filter->SetOutputOrigin( origin );

  InputImageType::DirectionType direction;
  direction.SetIdentity();
  filter->SetOutputDirection( direction );


  InputImageType::SizeType   size;
  size[0] = 512;  // number of pixels along X
  size[1] = 512;  // number of pixels along Y
  filter->SetSize( size );


  filter->SetInput( reader->GetOutput() );
  writer->SetInput( filter->GetOutput() );
  writer->Update();


  return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20111020/2c602c5f/attachment.htm>


More information about the Insight-users mailing list