[Insight-users] ImageWriter does not write Orientation (Direction
Cosines)
Bryn Lloyd
blloyd at bwh.harvard.edu
Thu Jul 14 15:29:51 EDT 2005
Hi Bill, anybody!
I am working with images that have a variable orientation relative to
another image. Which is why I decided to use the itkOrientedImage class.
My problem is when I try to write the image. Somehow the orientation is
lost. I try to save the image using the meta-header format (.mhd).
Is this a bug or am I doing something wrong?
Thanks!
Bryn
--------------
the header looks like this
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 0
CenterOfRotation = 0 0 0
AnatomicalOrientation = RSP
ElementSpacing = 0.859375 0.859375 5
DimSize = 256 256 1
ElementType = MET_DOUBLE
ElementDataFile = I020.raw
I would assume the TransformMatrix should contain the direction cosines!?
------------------
const unsigned int Dimension = 3;
typedef double PixelType;
typedef itk::OrientedImage< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( filenameGE5 );
reader->Update();
ImageType::Pointer image = reader->GetOutput();
this->ReadHeader( filenameGE5 );
/* set direction cosines */
typedef itk::Matrix<double,3,3> DirectionType;
DirectionType direction;
direction.Fill(0.0);
direction[0][0] = 1.0; // 1 0 0
direction[1][2] = 1.0; // 0 0 1
direction[2][1] = 1.0; // 0 1 0
std::cout << "New Direction Cosines " << std::endl << direction <<
std::endl;
image->SetDirection(direction);
std::cout << "Image Direction Cosines " << std::endl <<
image->GetDirection() << std::endl;
WriterType::Pointer writer = WriterType::New();
writer->SetInput( image );
writer->SetFileName( filenameOut );
writer->Update();
More information about the Insight-users
mailing list