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

Gordon Kindlmann gk at bwh.harvard.edu
Thu Jul 14 21:19:56 EDT 2005


hello,

>> 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
>
> Hmm.  Let me investigate this.

Okay, now I have looked into this, and I am convinced that something 
(outside NrrdIO) is transposing the direction cosines somewhere between 
the read and write.  I add some debugging code to the very end of 
NrrdImageIO::Read like:

   std::vector<double> dir(3);
   double spc;
   for (unsigned int axi=0; axi < 3; axi++) {
     spc = this->GetSpacing(axi);
     dir = this->GetDirection(axi);
     fprintf(stderr, "on read: dir[%d] = %g*(%g %g %g)\n", axi, spc,
             dir[0], dir[1], dir[2]);
   }

and got (via "bin/itkIOTests itkNrrdImageReadWriteTest", which as far 
as I can tell does the simplest possible sequence of reading an image 
and immediately writing it out, with no funny business in the middle):

on read: dir[0] = 1*(1 0 0)
on read: dir[1] = 1*(0.707107 0.707107 0)
on read: dir[2] = 1*(0 0 1)

which, by the way, is correct given the field in the NRRD header:

   space directions: (1,0,0) (0.707107,0.707107,0) (0,0,1)

And then, at the start of NrrdImageIO::Write, the same debugging code 
(except for changing "read" to "write") produces:

on write: dir[0] = 1*(1 0.707107 0)
on write: dir[1] = 1*(0 0.707107 0)
on write: dir[2] = 1*(0 0 1)

which is wrong, and which also corresponds to the behavior Bryn 
observed, whereby the direction cosines seem to have been transformed.

Can someone more versed than I in the details of Image IO help resolve 
where this transposition might be happening?

Karthik, can you reproduce the same behavior in the orientation 
handling that you just added to MetaIO?

thanks,
Gordon



More information about the Insight-users mailing list