[Insight-users] Problems with the orthogonal rotation matrix in versorRigid3DTransform
Luis Ibanez
luis.ibanez at kitware.com
Tue Dec 1 19:38:34 EST 2009
Hi Patrik,
Thanks for posting your code and the data.
Two things that you should try:
A) In your code, please insert a line:
trans.precision(15);
before each line that prints transform parameters.
for an explanation, please look at
http://www.cplusplus.com/reference/iostream/ios_base/precision/
Or (exclusive or)
B) You may want to try the classes
TransformFileWriter
TransformFileReader
that you will find in the directory
Insight/Code/Review
simply reconfigure ITK with CMake and turn ON
the CMake variables
* ITK_USE_REVIEW and
* ITK_USE_TRANSFORM_IO_FACTORIES
For an example of use of these classes, please see
Insight/Testing/Code/Review
itkTransformFileReaderWriterTest.cxx
Regards,
Luis
-------------------------------------------------------------
On Mon, Nov 30, 2009 at 10:38 AM, Patrik Brynolfsson
<patrik.brynolfsson at radfys.umu.se> wrote:
> Hello!
> I'm using version ITK 3.16.
> The code for writing to file is very simple and the relevant code is
> attached below:
> /* Get relevant parameters*/
> TransformType::MatrixType matrix = transform->GetRotationMatrix();
> TransformType::OffsetType offset = transform->GetOffset();
> TransformType::MatrixType invMatrix = matrix.GetInverse();
> TransformType::ParametersType finalParameters = transform->GetParameters();
> /* Write to file */
> std::ofstream trans(fileName,std::ios::app);
> trans << "Image: " << imageNumber << std::endl;
> trans << "\tMatrix:" << std::endl;
> trans << "\t\t" << matrix[0][0] <<" "<< matrix[0][1] <<" "<< matrix [0][2]
> << std::endl;
> trans << "\t\t" << matrix[1][0] <<" "<< matrix[1][1] <<" "<< matrix [1][2]
> << std::endl;
> trans << "\t\t" << matrix[2][0] <<" "<< matrix[2][1] <<" "<< matrix [2][2]
> << std::endl << std::endl;
> trans << "\tInverse matrix:" << std::endl;
> trans << "\t\t" << invMatrix[0][0] <<" "<< invMatrix[0][1] <<" "<< invMatrix
> [0][2] << std::endl;
> trans << "\t\t" << invMatrix[1][0] <<" "<< invMatrix[1][1] <<" "<< invMatrix
> [1][2] << std::endl;
> trans << "\t\t" << invMatrix[2][0] <<" "<< invMatrix[2][1] <<" "<< invMatrix
> [2][2] << std::endl << std::endl;
> trans << "\tOffset vector:" << std::endl;
> trans << "\t\t" << offset[0]<<" "<<offset[1]<<" "<<offset[2]<< std::endl <<
> std::endl;
> trans << "\tVersor transform:" << std::endl;
> trans << "\t\t" << finalParameters[0]<<" "<<finalParameters[1]<<"
> "<<finalParameters[2]<<" "<< finalParameters[3] <<" "<<finalParameters[4]
> <<" "<<finalParameters[5] <<std::endl << std::endl;
> trans << "\tCenter of Rotation:" << std::endl;
> trans << "\t\t" << transform->GetCenter()[0] <<" " <<
> transform->GetCenter()[1] <<" "<< transform->GetCenter()[2]<< std::endl <<
> std::endl;
> A result file might look like:
> Image: 1
> Matrix:
> 0.99998 -0.00105588 -0.00631213
> 0.00111111 0.999961 0.00875183
> 0.00630265 -0.00875866 0.999942
> Inverse matrix:
> 0.99998 0.00111111 0.00630265
> -0.00105588 0.999961 -0.00875866
> -0.00631213 0.00875183 0.999942
> Offset vector:
> 0.453916 -0.946682 0.388294
> Versor transform:
> -0.00437769 -0.00315374 0.000541755 0.259976 -0.727504 0.0970571
> Center of Rotation:
> -1.96057 31.6714 25.4334
> I hope this helps to fix the problem!
>
> Regards
> Patrik
> 2009/11/30 Luis Ibanez <luis.ibanez at kitware.com>
>>
>> Hi Patrik,
>>
>> 1) What version of ITK are you using ?
>>
>> 2) The error that you are getting indicates that the
>> matrix is non-orthogonal "to a certain precision level".
>>
>> 3) It would seem that the file where the transform
>> is saved is not using all the required precision.
>> This is a common problem when writing float/double
>> numbers as text.
>>
>> Could you please post to the mailing list the Transform
>> file that is not working for loading ?
>>
>> We can use it to track down the location where the
>> precision is being lost at the moment of writing.
>> Most likely what we need to fix is the "precision"
>> modifier of the ostream that is writing the data out.
>>
>> --
>>
>> If you are in a hurry, a work around would be for
>> you to "manually" save the array of parameters
>> of the transform. This will be more stable, since
>> it is saved as:
>>
>> Three Versor components for the rotation and
>> Three Vector components for the translation,
>> and, don't forget to save also the Fixed parameters
>> that will consist of the three components of the
>> center of rotation.
>>
>>
>>
>> Thanks
>>
>>
>> Luis
>>
>>
>>
>> ------------------------------------------------------------------------------
>> On Fri, Nov 27, 2009 at 9:01 AM, Patrik Brynolfsson
>> <patrik.brynolfsson at radfys.umu.se> wrote:
>> > Hello,
>> > I'm performing 3D rigid registration using the versorRigid3DTransform on
>> > a
>> > lot of images and save the resulting versors, rotation matrices, center
>> > of
>> > rotation and translations vectors in a text file connected to each
>> > image. My
>> > problem is that when I read the rotation matrix from file to perform the
>> > actual transform ITK complains, saying:
>> > "itk::ERROR: VersorRigid3DTransform(031BFC78): Attempting to set a
>> > non-orthogonal rotation matrix"
>> > It is the same matrix that ITK returned when the original registration
>> > was
>> > performed. How do I solve this?
>> > Thanks in advance,
>> > --
>> > Patrik Brynolfsson
>> >
>> >
>> >
>> > _____________________________________
>> > 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
>> >
>> >
>
>
>
> --
> Patrik Brynolfsson
>
>
>
More information about the Insight-users
mailing list