Hello!<div><br></div><div>I&#39;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="&#39;courier new&#39;, monospace">/* Get relevant parameters*/</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">TransformType::MatrixType matrix    = transform-&gt;GetRotationMatrix();</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">TransformType::OffsetType offset    = transform-&gt;GetOffset();</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">TransformType::MatrixType invMatrix = matrix.GetInverse();</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><div>
TransformType::ParametersType finalParameters = transform-&gt;GetParameters();</div></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">/* Write to file */</font></div>
<div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">std::ofstream trans(fileName,std::ios::app);</span></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;Image: &quot; &lt;&lt; imageNumber &lt;&lt; std::endl;</font></div>
<div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\tMatrix:&quot; &lt;&lt; std::endl;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; matrix[0][0] &lt;&lt;&quot; &quot;&lt;&lt; matrix[0][1] &lt;&lt;&quot; &quot;&lt;&lt; matrix [0][2] &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; matrix[1][0] &lt;&lt;&quot; &quot;&lt;&lt; matrix[1][1] &lt;&lt;&quot; &quot;&lt;&lt; matrix [1][2] &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; matrix[2][0] &lt;&lt;&quot; &quot;&lt;&lt; matrix[2][1] &lt;&lt;&quot; &quot;&lt;&lt; matrix [2][2] &lt;&lt; std::endl &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\tInverse matrix:&quot; &lt;&lt; std::endl;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; invMatrix[0][0] &lt;&lt;&quot; &quot;&lt;&lt; invMatrix[0][1] &lt;&lt;&quot; &quot;&lt;&lt; invMatrix [0][2] &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; invMatrix[1][0] &lt;&lt;&quot; &quot;&lt;&lt; invMatrix[1][1] &lt;&lt;&quot; &quot;&lt;&lt; invMatrix [1][2] &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; invMatrix[2][0] &lt;&lt;&quot; &quot;&lt;&lt; invMatrix[2][1] &lt;&lt;&quot; &quot;&lt;&lt; invMatrix [2][2] &lt;&lt; std::endl &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\tOffset vector:&quot; &lt;&lt; std::endl;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; offset[0]&lt;&lt;&quot; &quot;&lt;&lt;offset[1]&lt;&lt;&quot; &quot;&lt;&lt;offset[2]&lt;&lt; std::endl &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\tVersor transform:&quot; &lt;&lt; std::endl;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; finalParameters[0]&lt;&lt;&quot; &quot;&lt;&lt;finalParameters[1]&lt;&lt;&quot; &quot;&lt;&lt;finalParameters[2]&lt;&lt;&quot; &quot;<span class="Apple-style-span" style="font-family: arial; "><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">&lt;&lt; finalParameters[3] &lt;&lt;&quot; &quot;&lt;&lt;finalParameters[4] &lt;&lt;&quot; &quot;&lt;&lt;finalParameters[5] &lt;&lt;std::endl &lt;&lt; std::endl;</font></span></font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\tCenter of Rotation:&quot; &lt;&lt; std::endl;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">trans &lt;&lt; &quot;\t\t&quot; &lt;&lt; transform-&gt;GetCenter()[0] &lt;&lt;&quot; &quot; &lt;&lt; transform-&gt;GetCenter()[1] &lt;&lt;&quot; &quot;&lt;&lt; transform-&gt;GetCenter()[2]&lt;&lt; std::endl &lt;&lt; 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="&#39;courier new&#39;, monospace">Image: 1</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Matrix:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, 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="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, 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="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">0.00630265 -0.00875866 0.999942</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Inverse matrix:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, 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="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, 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="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-0.00631213 0.00875183 0.999942</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Offset vector:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">0.453916 -0.946682 0.388294</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Versor transform:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-0.00437769 -0.00315374 0.000541755 0.259976 -0.727504 0.0970571</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Center of Rotation:</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                </font></span><font class="Apple-style-span" face="&#39;courier new&#39;, 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">&lt;<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>&gt;</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 &quot;to a certain precision level&quot;.<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 &quot;precision&quot;<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 &quot;manually&quot; 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&#39;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>
&lt;<a href="mailto:patrik.brynolfsson@radfys.umu.se">patrik.brynolfsson@radfys.umu.se</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt; I&#39;m performing 3D rigid registration using the versorRigid3DTransform on a<br>
&gt; lot of images and save the resulting versors, rotation matrices, center of<br>
&gt; rotation and translations vectors in a text file connected to each image. My<br>
&gt; problem is that when I read the rotation matrix from file to perform the<br>
&gt; actual transform ITK complains, saying:<br>
&gt; &quot;itk::ERROR: VersorRigid3DTransform(031BFC78): Attempting to set a<br>
&gt; non-orthogonal rotation matrix&quot;<br>
&gt; It is the same matrix that ITK returned when the original registration was<br>
&gt; performed. How do I solve this?<br>
&gt; Thanks in advance,<br>
&gt; --<br>
&gt; Patrik Brynolfsson<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br><br clear="all"><br>-- <br>Patrik Brynolfsson<br><br><br>
</div>