[Insight-users] [ITK Community] 4x4 matrix to itkTransform
Matt McCormick
matt.mccormick at kitware.com
Thu Jan 30 11:23:16 EST 2014
Hi Vikash,
To figure this out, start at the AffineTransform Doxygen documentation [1].
Looking at the Inheritance Diagram, we see it inherits from
MatrixOffsetTransformBase [2]. Looking at the implementation of
SetParameters in MatrixOffsetTransformBase [3] shows the order of the
parameters.
We can verify with some code [4]. The output is:
matrix4x4: 1 2 3 4
5 6 7 8
9 10 11 12
0 0 0 1
extendedPoint: [3.3, 2.8, -4.7, 1]
transformedExtendedPoint: [-1.2, 8.4, 18, 1]
parameters: [1, 2, 3, 5, 6, 7, 9, 10, 11, 4, 8, 12]
transform: AffineTransform (0xe89710)
RTTI typeinfo: itk::AffineTransform<float, 3u>
Reference Count: 2
Modified Time: 16
Debug: Off
Object Name:
Observers:
none
Matrix:
1 2 3
5 6 7
9 10 11
Offset: [4, 8, 12]
Center: [0, 0, 0]
Translation: [4, 8, 12]
Inverse:
1 0 0
0 1 0
0 0 1
Singular: 1
transformedPoint: [-1.2, 8.4, 18]
And the output file:
#Insight Transform File V1.0
#Transform 0
Transform: AffineTransform_float_3_3
Parameters: 1 2 3 5 6 7 9 10 11 4 8 12
FixedParameters: 0 0 0
Hope this helps,
Matt
[1] http://www.itk.org/Doxygen/html/classitk_1_1AffineTransform.html
[2] http://www.itk.org/Doxygen/html/classitk_1_1MatrixOffsetTransformBase.html
[3] http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx;h=24bd8d5f0cc64dfdf6b283a37cd8d460802fe2ad;hb=HEAD#l602
[4] https://gist.github.com/thewtex/8712205
On Tue, Jan 28, 2014 at 3:43 PM, Vikash Gupta <vikash.gupta at inria.fr> wrote:
> Hi Matt,
> Thanks for the reply...
> However in [1] the test.tfm (which I believe is a matrix file) is not there. but I can try to code. Just so that I am clear
> If the input matrix is
>
> a b c d
> e f g h
> i j k l
> 0 0 0 1
>
> The parameters in the transform file will look like
>
> a b c e f g i j k d h l
>
> Am i right ?
>
> Thanks
> Vikash
>
> ----- Original Message -----
>> From: "Matt McCormick" <matt.mccormick at kitware.com>
>> To: "Vikash Gupta" <vikash.gupta at inria.fr>
>> Cc: "insight-users at itk org" <insight-users at itk.org>
>> Sent: Tuesday, January 28, 2014 8:11:31 PM
>> Subject: Re: [ITK Community] [Insight-users] 4x4 matrix to itkTransform
>>
>> Hi Vikash,
>>
>> The Transform of interest can be instantiated and then its values set
>> with the "SetParameters" method. See the transform code for order.
>> For an affine transform like the one referenced, note that it is
>> typically stored as affine matrix + translation, eliminating the need
>> for the "0 0 0 1" in the bottom row. There is also often a center of
>> rotation that is stored.
>>
>> The transform can then be written to file with the
>> TransformFileWriterTemplate class [1]
>>
>> Hope this helps,
>> Matt
>>
>> [1]
>> http://www.itk.org/Doxygen/html/classitk_1_1TransformFileWriterTemplate.html
>>
>> On Tue, Jan 28, 2014 at 1:27 PM, Vikash Gupta <vikash.gupta at inria.fr>
>> wrote:
>> > Hey everyone
>> > I am little bit lost like if there is a tool that exist that will
>> > convert a
>> > 4x4 matrix to a ITKTransform type
>> >
>> > For example, essentially
>> > input format
>> >
>> > 0.990242 0.0089482 0.0115564 -55.2129
>> > -0.00411503 0.978607 0.0120489 -60.1255
>> > -0.00965018 -0.00686595 0.979628 74.2065
>> > 0 0 0 1
>> >
>> > Output
>> > #Insight Transform File V1.0
>> > # Transform 0
>> > Transform: AffineTransform_double_3_3
>> > Parameters: -0.997192 0.0283671 -0.0693022 0.0158514 0.984462
>> > 0.174879
>> > -0.0731862 -0.173289 0.982148 -0.206132 -33.1051 7.77696
>> > FixedParameters: 0 0 0
>> >
>> >
>> > Any help would be really appreciated.
>> >
>> > Thanks
>> > Vikash
>> >
>> > _____________________________________
>> > 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
>> >
>>
More information about the Insight-users
mailing list