<div dir="ltr"><div>Sorry. Forgot to include the code in the earlier post<br><br></div>%The affine parameters come in the vAffineParameters vector to the function<br><br><div><div>typedef itk::AffineTransform< double, 2 > TransformType;<br>
TransformType::Pointer transform = TransformType::New();<br> TransformType::ParametersType affParameters(transform->GetNumberOfParameters());<br> for(int i=0;i<6;i++)<br> affParameters[i] = vAffineParameters[i];<br>
transform->SetParameters(affParameters);<br> <br> double center[2];<br> center[0] = vAffineParameters[6];<br> center[1] = vAffineParameters[7];<br> transform->SetCenter(center);<br><br> TransformType::InverseTransformBasePointer inverse = transform->GetInverseTransform();<br>
TransformType::ParametersType inverseParameters = inverse->GetParameters();<br> <br> float a11 = inverseParameters[0];<br> float a12 = inverseParameters[1];<br> float a21 = inverseParameters[2];<br> float a22 = inverseParameters[3];<br>
float Tx = inverseParameters[4]; //Tx and Ty seems to be not correct?<br> float Ty = inverseParameters[5]; //Tx and Ty seems to be not correct? <br> Cx = transform->GetCenter()[0]; //Is there a way to get the center from the inverse transform?<br>
Cy = transform->GetCenter()[1];<br><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 12, 2014 at 9:40 AM, John D <span dir="ltr"><<a href="mailto:john.dz.eis@gmail.com" target="_blank">john.dz.eis@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>Hello users,<br><br> I have a problem where I need to compute the inverse of an affine transform in 2D.<br>
<br></div>I am seeing a problem in the results. Lets say my affine matrix has just pure rotation at 45 degree.<br>
<br>So my A matrix is [cost(45) -sin(45); sin(45 cos(45)]. There is no translation and so [Tx Ty] = [0 0]. I am trying to rotate a square that is 6000 on each side and my center of rotation is mid point of the square [3000 3000]<br>
<br></div>When I use transform->GetInverseTransform() to find the inverse transform<br><br></div>I am getting the correct coordinates for the A matrix. However the returned translations in the inverse matrix are wrong. I would have expected the Tx, Ty to be [0 0] in the inverse also since rotation is wrt to the center. However I am getting [Tx, Ty] = [3000, -1243]<br>
<br></div>What am I missing? Also when computing the inverse, will the center of rotation get changed? How can I get the new center of rotation?<br><br></div>Thanks,<br></div>John<br><div><div><br><br></div></div></div>
</blockquote></div><br></div>