Hello!<div><br></div><div>I'm using version ITK 3.16. </div><div><br></div><div>The code for writing to file is very simple and the relevant code is attached below:</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">/* Get relevant parameters*/</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">TransformType::MatrixType matrix = transform->GetRotationMatrix();</font></div><div><font class="Apple-style-span" face="'courier new', monospace">TransformType::OffsetType offset = transform->GetOffset();</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">TransformType::MatrixType invMatrix = matrix.GetInverse();</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><div>
TransformType::ParametersType finalParameters = transform->GetParameters();</div></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">/* Write to file */</font></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">std::ofstream trans(fileName,std::ios::app);</span></div><div><font class="Apple-style-span" face="'courier new', monospace">trans << "Image: " << imageNumber << std::endl;</font></div>
<div><div><font class="Apple-style-span" face="'courier new', monospace">trans << "\tMatrix:" << std::endl;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << matrix[0][0] <<" "<< matrix[0][1] <<" "<< matrix [0][2] << std::endl;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << matrix[1][0] <<" "<< matrix[1][1] <<" "<< matrix [1][2] << std::endl;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << matrix[2][0] <<" "<< matrix[2][1] <<" "<< matrix [2][2] << std::endl << std::endl;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\tInverse matrix:" << std::endl;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << invMatrix[0][0] <<" "<< invMatrix[0][1] <<" "<< invMatrix [0][2] << std::endl;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << invMatrix[1][0] <<" "<< invMatrix[1][1] <<" "<< invMatrix [1][2] << std::endl;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << invMatrix[2][0] <<" "<< invMatrix[2][1] <<" "<< invMatrix [2][2] << std::endl << std::endl;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\tOffset vector:" << std::endl;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << offset[0]<<" "<<offset[1]<<" "<<offset[2]<< std::endl << std::endl;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\tVersor transform:" << std::endl;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << finalParameters[0]<<" "<<finalParameters[1]<<" "<<finalParameters[2]<<" "<span class="Apple-style-span" style="font-family: arial; "><font class="Apple-style-span" face="'courier new', monospace"><< finalParameters[3] <<" "<<finalParameters[4] <<" "<<finalParameters[5] <<std::endl << std::endl;</font></span></font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">trans << "\tCenter of Rotation:" << std::endl;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">trans << "\t\t" << transform->GetCenter()[0] <<" " << transform->GetCenter()[1] <<" "<< transform->GetCenter()[2]<< std::endl << std::endl;</font></div>
<div><br></div><div>A result file might look like:</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">Image: 1</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">Matrix:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">0.99998 -0.00105588 -0.00631213</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">0.00111111 0.999961 0.00875183</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">0.00630265 -0.00875866 0.999942</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">Inverse matrix:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">0.99998 0.00111111 0.00630265</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">-0.00105588 0.999961 -0.00875866</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">-0.00631213 0.00875183 0.999942</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">Offset vector:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">0.453916 -0.946682 0.388294</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">Versor transform:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">-0.00437769 -0.00315374 0.000541755 0.259976 -0.727504 0.0970571</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">Center of Rotation:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">-1.96057 31.6714 25.4334</font></div>
</div><div><br></div>I hope this helps to fix the problem!</div><div><br></div><div><br></div><div>Regards</div><div><br></div><div>Patrik</div><div><br><div class="gmail_quote">2009/11/30 Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Patrik,<br>
<br>
1) What version of ITK are you using ?<br>
<br>
2) The error that you are getting indicates that the<br>
matrix is non-orthogonal "to a certain precision level".<br>
<br>
3) It would seem that the file where the transform<br>
is saved is not using all the required precision.<br>
This is a common problem when writing float/double<br>
numbers as text.<br>
<br>
Could you please post to the mailing list the Transform<br>
file that is not working for loading ?<br>
<br>
We can use it to track down the location where the<br>
precision is being lost at the moment of writing.<br>
Most likely what we need to fix is the "precision"<br>
modifier of the ostream that is writing the data out.<br>
<br>
--<br>
<br>
If you are in a hurry, a work around would be for<br>
you to "manually" save the array of parameters<br>
of the transform. This will be more stable, since<br>
it is saved as:<br>
<br>
Three Versor components for the rotation and<br>
Three Vector components for the translation,<br>
and, don't forget to save also the Fixed parameters<br>
that will consist of the three components of the<br>
center of rotation.<br>
<br>
<br>
<br>
Thanks<br>
<br>
<br>
Luis<br>
<br>
<br>
------------------------------------------------------------------------------<br>
<div><div></div><div class="h5">On Fri, Nov 27, 2009 at 9:01 AM, Patrik Brynolfsson<br>
<<a href="mailto:patrik.brynolfsson@radfys.umu.se">patrik.brynolfsson@radfys.umu.se</a>> wrote:<br>
> Hello,<br>
> I'm performing 3D rigid registration using the versorRigid3DTransform on a<br>
> lot of images and save the resulting versors, rotation matrices, center of<br>
> rotation and translations vectors in a text file connected to each image. My<br>
> problem is that when I read the rotation matrix from file to perform the<br>
> actual transform ITK complains, saying:<br>
> "itk::ERROR: VersorRigid3DTransform(031BFC78): Attempting to set a<br>
> non-orthogonal rotation matrix"<br>
> It is the same matrix that ITK returned when the original registration was<br>
> performed. How do I solve this?<br>
> Thanks in advance,<br>
> --<br>
> Patrik Brynolfsson<br>
><br>
><br>
><br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
><br>
</blockquote></div><br><br clear="all"><br>-- <br>Patrik Brynolfsson<br><br><br>
</div>