[Insight-users] ImageWriter does not write Orientation (Direction Cosines)

Karthik Krishnan Karthik.Krishnan at kitware.com
Thu Jul 14 19:21:28 EDT 2005


Bryn Lloyd wrote:

>Hi Karthik and Gordon and all listening,
>
>Thanks, the MetaIO works for writing now.
>It doesn't seem to read the information though! I read a identy matrix.
>  
>
Oops..... Thanks for pointing this out. I forgot to fix the reader. Will 
do that now.

>I'm a bit confused about how the NRRD IO works. Why does it rescale the
>direction cosines at all? I would prefer the assumption that the user has
>set them correctly...
>
>This is what happens (NRRD):
>
>Say I set the following direction cosines:
>
>0.286406 0.118831 0.950711
>0.948371 -0.176269 -0.263669
>0.136249 0.977143 -0.16318
>
>then the NRRD IO writes:
>
>space directions:
>(0.24613,0.10212,0.817017)
>(0.815007,-0.151481,-0.22659)
>(0.681244,4.88571,-0.815902)
>
>if I read them with the NRRD IO, I read:
>
>0.286406 0.948371 0.136249
>0.118831 -0.176269 0.977143
>0.950711 -0.263668 -0.163181
>
>These are the original direction cosines, just they are transposed...
>
>and if I write again :
>
>space directions:
>(0.24613,0.815007,0.117089)
>(0.10212,-0.151481,0.839733)
>(4.75355,-1.31834,-0.815902)
>
>What is happening??
>
>Is there something I don't understand about the direction cosines, or is
>this a bug?
>
>
>Thanks
>
>Bryn
>
>BTW
>There is a nice summary of the direction cosines at:
>http://mathworld.wolfram.com/DirectionCosine.html
>
>
>
>
><quote who="Karthik Krishnan">
>  
>
>>Bryn,
>>
>>Just committed a fix in CVS. Let me know if it works ok.
>>
>>Thanks
>>regards
>>Karthik
>>
>>Gordon Kindlmann wrote:
>>
>>    
>>
>>>hello,
>>>
>>>One possible option, if you are using the latest CVS version of ITK,
>>>is to save the image in NRRD format (filename ends with ".nhdr" for
>>>separate header and data, or ".nrrd" for one file).  This saves the
>>>direction cosines (after scaling by the spacings) in the "space
>>>directions:" field of the NRRD header.  Right now this only handles
>>>scalar datasets; non-scalar datasets should be handled soon.
>>>
>>>Gordon
>>>
>>>On Jul 14, 2005, at 3:29 PM, Bryn Lloyd wrote:
>>>
>>>      
>>>
>>>>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();
>>>>
>>>>
>>>>_______________________________________________
>>>>Insight-users mailing list
>>>>Insight-users at itk.org
>>>>http://www.itk.org/mailman/listinfo/insight-users
>>>>        
>>>>
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>>      
>>>
>
>
>
>  
>


More information about the Insight-users mailing list