[Insight-users] [ITK Community] inverse of affine transform using transform->GetInverseTransform();
Matt McCormick
matt.mccormick at kitware.com
Wed Feb 12 13:02:06 EST 2014
Hi John,
Could a fully buildable version of the code demonstrating the issue be
posted, possibly through a Github Gist [1]?
The center of the inverse should be the same, and it is important to set it
before calling GetInverse() as documented here: [2].
Hope this helps,
Matt
[1] https://gist.github.com/
[2]
http://www.itk.org/Doxygen/html/classitk_1_1MatrixOffsetTransformBase.html#a1e97fbe21d53aa805a9692ca9ab95fdb
On Wed, Feb 12, 2014 at 12:43 PM, John D <john.dz.eis at gmail.com> wrote:
> Sorry. Forgot to include the code in the earlier post
>
> %The affine parameters come in the vAffineParameters vector to the function
>
> typedef itk::AffineTransform< double, 2 > TransformType;
> TransformType::Pointer transform = TransformType::New();
> TransformType::ParametersType
> affParameters(transform->GetNumberOfParameters());
> for(int i=0;i<6;i++)
> affParameters[i] = vAffineParameters[i];
> transform->SetParameters(affParameters);
>
> double center[2];
> center[0] = vAffineParameters[6];
> center[1] = vAffineParameters[7];
> transform->SetCenter(center);
>
> TransformType::InverseTransformBasePointer inverse =
> transform->GetInverseTransform();
> TransformType::ParametersType inverseParameters =
> inverse->GetParameters();
>
> float a11 = inverseParameters[0];
> float a12 = inverseParameters[1];
> float a21 = inverseParameters[2];
> float a22 = inverseParameters[3];
> float Tx = inverseParameters[4]; //Tx and Ty seems to be not correct?
> float Ty = inverseParameters[5]; //Tx and Ty seems to be not correct?
> Cx = transform->GetCenter()[0]; //Is there a way to get the center
> from the inverse transform?
> Cy = transform->GetCenter()[1];
>
>
>
> On Wed, Feb 12, 2014 at 9:40 AM, John D <john.dz.eis at gmail.com> wrote:
>
>> Hello users,
>>
>> I have a problem where I need to compute the inverse of an affine
>> transform in 2D.
>>
>> I am seeing a problem in the results. Lets say my affine matrix has just
>> pure rotation at 45 degree.
>>
>> 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]
>>
>> When I use transform->GetInverseTransform() to find the inverse transform
>>
>> 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]
>>
>> 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?
>>
>> Thanks,
>> John
>>
>>
>>
>
> _____________________________________
> 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.php
>
> 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
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20140212/bf24d80e/attachment.html>
More information about the Insight-users
mailing list