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

Bill Lorensen bill.lorensen at gmail.com
Tue Sep 28 23:42:01 EDT 2010


Origin, spacing and directions should be set in the
ReadImageInformation method. If you look at the ImageFileReader,
youu'll see that the GenerateOutputInformation method calls the
ImageIO's ReadImageInformation method.

Bill

On Tue, Sep 28, 2010 at 12:55 PM, Michael Jackson
<mike.jackson at bluequartz.net> wrote:
>  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
>
>
>
> _____________________________________
> 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.html
>
> 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://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list