[Insight-users] New Image Reader not setting the Spacing/Origin correctly

Michael Jackson mike.jackson at bluequartz.net
Tue Sep 28 12:55:23 EDT 2010


  I am developing a new ImageIOBase derived class to read some  
microscopy data. During the read() method I have the following code:

   this->SetSpacing(0, reader.getXStep());
   this->SetSpacing(1, reader.getYStep());

   this->SetOrigin(0, xpos[0]);
   this->SetOrigin(1, ypos[0]);

   std::cout << "Ang Spacing: " << m_Spacing[0] << ", " <<  
m_Spacing[1] << std::endl;
   std::cout << "Ang Origin : " << m_Origin[0] << ", " << m_Origin[1]  
<< std::endl;

Which correctly prints out the spacing and origin of the data.

But when I use the reader in my actual program I get origin and  
spacing to 0.0 and 1.0 (which are the default values set in the  
contructor).

   itk::AngImageIOFactory::RegisterOneFactory();
   const    unsigned int   Dimension = 2;
   typedef  unsigned char  PixelType;

   typedef itk::Image< PixelType, Dimension >  MovingImageType;
   typedef itk::ImageFileReader< MovingImageType >  
MovingImageReaderType;
   MovingImageReaderType::Pointer movingImageReader =  
MovingImageReaderType::New();

   movingImageReader->SetFileName( argv[2] );
   movingImageReader->Update();

   MovingImageType::Pointer movingImage = movingImageReader- 
 >GetOutput();
   MovingImageType::PointType movingOrigin = movingImage->GetOrigin();
   MovingImageType::SizeType movingSize = movingImage- 
 >GetLargestPossibleRegion().GetSize();
   MovingImageType::SpacingType movingSpacing = movingImage- 
 >GetSpacing();

   std::cout << "Moving Image Size: " << movingSize[0] << " x " <<  
movingSize[1] << std::endl;
   std::cout << "Moving Image Origin: " << movingOrigin[0] << ", " <<  
movingOrigin[1] << std::endl;
   std::cout << "Moving Image Spacing: " << movingSpacing[0] << ", "<<  
movingSpacing[1] << std::endl;

The output from the above is:

Moving Image Size: 189 x 201
Moving Image Origin: 0, 0
Moving Image Spacing: 1, 1

Where is the "correct" location to set the origin/spacing if I am  
implementing a new ImageIOBase reader?

Thanks
___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jackson at bluequartz.net
BlueQuartz Software               Dayton, Ohio





More information about the Insight-users mailing list