[vtkusers] image orientation

Gao, Yi gaoyi.cn at gmail.com
Wed May 8 23:11:16 EDT 2013


Dear all,

I read a .mha meta image file using vtkMetaImageReader, then use the input
image to initialize a new image, and output with vtkMetaImageWriter. The
code is:

    vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
    reader->SetFileName(argv[1]);
    reader->Update();
    vtkSmartPointer<vtkImageData> img = reader->GetOutput();


    vtkSmartPointer<vtkImageData> outImage =
vtkSmartPointer<vtkImageData>::New();
    outImage->SetDimensions(img->GetDimensions());
    outImage->SetOrigin(img->GetOrigin());
    outImage->SetSpacing(img->GetSpacing());
    outImage->SetInformation(img->GetInformation());
    outImage->SetNumberOfScalarComponents(1);
    outImage->SetScalarType(img->GetScalarType());
    outImage->AllocateScalars();

    vtkSmartPointer<vtkMetaImageWriter> writer =
vtkSmartPointer<vtkMetaImageWriter>::New();
    writer->SetFileName("aa.mhd");
    writer->SetRAWFileName("aa.raw");
    writer->SetInput(outImage);
    writer->Write();



But the output image header information is different from the input. The
input image has the header:
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = False
TransformMatrix = 0 1 0 0 0 -1 -1 0 0
Offset = 86.6449 -133.929 116.786
CenterOfRotation = 0 0 0
AnatomicalOrientation = ASL
ElementSpacing = 1 1 1.3
DimSize = 256 256 130
ElementType = MET_SHORT
ElementDataFile = LOCAL



The output image header is:

ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = True
CompressedDataSize = 16584
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 86.6449 -133.929 116.786
CenterOfRotation = 0 0 0
ElementSpacing = 1 1 1.3
DimSize = 256 256 130
AnatomicalOrientation = ???
ElementType = MET_SHORT
ElementDataFile = aa.raw


The AnatomicalOrientation and TransformMatrix are different...

Could I get some advice on how to copy the input image's such info to the
output image?

Thank you!

Best,
yi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130508/cd025263/attachment.htm>


More information about the vtkusers mailing list