Transformation matrices in .tfm files do not match those displayed in Slicer upon load

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Aaron Ward
Hello,

I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
under Windows Server 2007 SP2.  When I create a transform in the
Transforms module (by manipulating the slider bars for translation and
rotation) and then save the transform to disk, the numbers in the .tfm
file do not represent the same matrix as shown in the Slicer interface
when this .tfm file is loaded.  Why does this behaviour occur?

Thanks,
Aaron Ward
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

pieper
Administrator
Hi Aaron -

Could you be more specific about what is different?

Perhaps you are seeing the LPS/RAS differences described here:

> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems

-Steve

On 03/01/2011 02:03 PM, Aaron Ward wrote:

> Hello,
>
> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
> under Windows Server 2007 SP2.  When I create a transform in the
> Transforms module (by manipulating the slider bars for translation and
> rotation) and then save the transform to disk, the numbers in the .tfm
> file do not represent the same matrix as shown in the Slicer interface
> when this .tfm file is loaded.  Why does this behaviour occur?
>
> Thanks,
> Aaron Ward
> _______________________________________________
> slicer-users mailing list
> [hidden email]
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Aaron Ward
Hi Steve,

Thanks for the quick reply!  Here is a specific example.  If I load
the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
choosing "Load Transforms" in the transforms module:

#Insight Transform File V1.0
# Transform 0
Transform: AffineTransform_double_3_3
Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
-0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
FixedParameters: 0 0 0

I see the following matrix in the Transforms window:

0.996918 -0.078459 -0.000000 6.899965
0.068016 0.864225 -0.498488 -95.999726
0.039111 0.496951 0.866896 266.299559
-0.000000 0.000000 -0.000000 1.000000

It looks like the entries corresponding to the translation do not
match those in the .tfm file.

Thanks,
Aaron

On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper <[hidden email]> wrote:

> Hi Aaron -
>
> Could you be more specific about what is different?
>
> Perhaps you are seeing the LPS/RAS differences described here:
>
>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>
> -Steve
>
> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>
>> Hello,
>>
>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>> under Windows Server 2007 SP2.  When I create a transform in the
>> Transforms module (by manipulating the slider bars for translation and
>> rotation) and then save the transform to disk, the numbers in the .tfm
>> file do not represent the same matrix as shown in the Slicer interface
>> when this .tfm file is loaded.  Why does this behaviour occur?
>>
>> Thanks,
>> Aaron Ward
>> _______________________________________________
>> slicer-users mailing list
>> [hidden email]
>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>> To unsubscribe: send email to
>> [hidden email] with unsubscribe as the
>> subject
>
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Dominik Meier
Hi Aaron

I've grappled with this also. The reason I think is that rotations are relative to the image origin, which is not included in what is displayed in the transforms module, so combined rotations & translations will show some differences, although they do the same thing.

Dominik

On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:

> Hi Steve,
>
> Thanks for the quick reply!  Here is a specific example.  If I load
> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
> choosing "Load Transforms" in the transforms module:
>
> #Insight Transform File V1.0
> # Transform 0
> Transform: AffineTransform_double_3_3
> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
> FixedParameters: 0 0 0
>
> I see the following matrix in the Transforms window:
>
> 0.996918 -0.078459 -0.000000 6.899965
> 0.068016 0.864225 -0.498488 -95.999726
> 0.039111 0.496951 0.866896 266.299559
> -0.000000 0.000000 -0.000000 1.000000
>
> It looks like the entries corresponding to the translation do not
> match those in the .tfm file.
>
> Thanks,
> Aaron
>
> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper <[hidden email]> wrote:
>> Hi Aaron -
>>
>> Could you be more specific about what is different?
>>
>> Perhaps you are seeing the LPS/RAS differences described here:
>>
>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>
>> -Steve
>>
>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>
>>> Hello,
>>>
>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>> under Windows Server 2007 SP2.  When I create a transform in the
>>> Transforms module (by manipulating the slider bars for translation and
>>> rotation) and then save the transform to disk, the numbers in the .tfm
>>> file do not represent the same matrix as shown in the Slicer interface
>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>
>>> Thanks,
>>> Aaron Ward
>>> _______________________________________________
>>> slicer-users mailing list
>>> [hidden email]
>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>> To unsubscribe: send email to
>>> [hidden email] with unsubscribe as the
>>> subject
>>
> _______________________________________________
> slicer-users mailing list
> [hidden email]
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
> To unsubscribe: send email to [hidden email] with unsubscribe as the subject

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Aaron Ward
Hi Dominik,

Thanks for the reply.  What I find confusing is that the behaviour I
described below is observed even when no image is loaded, so there is
no image origin to speak of.

Aaron

On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier <[hidden email]> wrote:

> Hi Aaron
>
> I've grappled with this also. The reason I think is that rotations are relative to the image origin, which is not included in what is displayed in the transforms module, so combined rotations & translations will show some differences, although they do the same thing.
>
> Dominik
>
> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>
>> Hi Steve,
>>
>> Thanks for the quick reply!  Here is a specific example.  If I load
>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>> choosing "Load Transforms" in the transforms module:
>>
>> #Insight Transform File V1.0
>> # Transform 0
>> Transform: AffineTransform_double_3_3
>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>> FixedParameters: 0 0 0
>>
>> I see the following matrix in the Transforms window:
>>
>> 0.996918 -0.078459 -0.000000 6.899965
>> 0.068016 0.864225 -0.498488 -95.999726
>> 0.039111 0.496951 0.866896 266.299559
>> -0.000000 0.000000 -0.000000 1.000000
>>
>> It looks like the entries corresponding to the translation do not
>> match those in the .tfm file.
>>
>> Thanks,
>> Aaron
>>
>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper <[hidden email]> wrote:
>>> Hi Aaron -
>>>
>>> Could you be more specific about what is different?
>>>
>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>
>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>
>>> -Steve
>>>
>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>
>>>> Hello,
>>>>
>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>> Transforms module (by manipulating the slider bars for translation and
>>>> rotation) and then save the transform to disk, the numbers in the .tfm
>>>> file do not represent the same matrix as shown in the Slicer interface
>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>
>>>> Thanks,
>>>> Aaron Ward
>>>> _______________________________________________
>>>> slicer-users mailing list
>>>> [hidden email]
>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>> To unsubscribe: send email to
>>>> [hidden email] with unsubscribe as the
>>>> subject
>>>
>> _______________________________________________
>> slicer-users mailing list
>> [hidden email]
>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>
>



--
Aaron D. Ward, PhD
Cancer Care Ontario Research Chair in Cancer Imaging
Assistant Professor, Medical Biophysics & Biomedical Engineering
Schulich School of Medicine and Dentistry
The University of Western Ontario

Co-Principal Investigator, Imaging Research Laboratory
Gerald C. Baines Centre for Translational Cancer Research
Room A3-121, London Regional Cancer Program
London Health Sciences Centre
790 Commissioners Road East
London, ON, Canada  N6A 4L6

Tel: 519-685-8500 x 56846
Fax: 519-685-8658
E-mail: [hidden email]
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Andrey Fedorov
Aaron,

The center of rotation is always RAS space origin (0,0,0), not image
origin. (0,0,0) is the origin of Slicer "universe".

Andrey


On Tue, Mar 1, 2011 at 16:29, Aaron Ward <[hidden email]> wrote:

> Hi Dominik,
>
> Thanks for the reply.  What I find confusing is that the behaviour I
> described below is observed even when no image is loaded, so there is
> no image origin to speak of.
>
> Aaron
>
> On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier <[hidden email]> wrote:
>> Hi Aaron
>>
>> I've grappled with this also. The reason I think is that rotations are relative to the image origin, which is not included in what is displayed in the transforms module, so combined rotations & translations will show some differences, although they do the same thing.
>>
>> Dominik
>>
>> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>>
>>> Hi Steve,
>>>
>>> Thanks for the quick reply!  Here is a specific example.  If I load
>>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>>> choosing "Load Transforms" in the transforms module:
>>>
>>> #Insight Transform File V1.0
>>> # Transform 0
>>> Transform: AffineTransform_double_3_3
>>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>>> FixedParameters: 0 0 0
>>>
>>> I see the following matrix in the Transforms window:
>>>
>>> 0.996918 -0.078459 -0.000000 6.899965
>>> 0.068016 0.864225 -0.498488 -95.999726
>>> 0.039111 0.496951 0.866896 266.299559
>>> -0.000000 0.000000 -0.000000 1.000000
>>>
>>> It looks like the entries corresponding to the translation do not
>>> match those in the .tfm file.
>>>
>>> Thanks,
>>> Aaron
>>>
>>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper <[hidden email]> wrote:
>>>> Hi Aaron -
>>>>
>>>> Could you be more specific about what is different?
>>>>
>>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>>
>>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>>
>>>> -Steve
>>>>
>>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>>
>>>>> Hello,
>>>>>
>>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>>> Transforms module (by manipulating the slider bars for translation and
>>>>> rotation) and then save the transform to disk, the numbers in the .tfm
>>>>> file do not represent the same matrix as shown in the Slicer interface
>>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>>
>>>>> Thanks,
>>>>> Aaron Ward
>>>>> _______________________________________________
>>>>> slicer-users mailing list
>>>>> [hidden email]
>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>> To unsubscribe: send email to
>>>>> [hidden email] with unsubscribe as the
>>>>> subject
>>>>
>>> _______________________________________________
>>> slicer-users mailing list
>>> [hidden email]
>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>
>>
>
>
>
> --
> Aaron D. Ward, PhD
> Cancer Care Ontario Research Chair in Cancer Imaging
> Assistant Professor, Medical Biophysics & Biomedical Engineering
> Schulich School of Medicine and Dentistry
> The University of Western Ontario
>
> Co-Principal Investigator, Imaging Research Laboratory
> Gerald C. Baines Centre for Translational Cancer Research
> Room A3-121, London Regional Cancer Program
> London Health Sciences Centre
> 790 Commissioners Road East
> London, ON, Canada  N6A 4L6
>
> Tel: 519-685-8500 x 56846
> Fax: 519-685-8658
> E-mail: [hidden email]
> _______________________________________________
> slicer-users mailing list
> [hidden email]
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Aaron Ward
Hi Andrey,

Thanks for your help.

I should probably clarify my question.  There is no image involved.
If I do the following:

1. Launch 3D Slicer.
2. Create a transform.
3. Adjust it by adjusting the 6 slider bars in the Transforms module.
4. Save the transform as a .tfm file.
5. Inspect the contents of the .tfm file in a text editor, and compare
them to what is shown in the 4x4 matrix in the Transforms module.

In step 5, the contents of the .tfm file and what is displayed in the
Transforms module do not match.

There is no image, and no image origin involved anywhere in the above process.

Any insights would be appreciated as to why 3D Slicer would save
different a different matrix to the .tfm file than that shown in the
Transforms window.

Thanks,
Aaron

On Tue, Mar 1, 2011 at 4:43 PM, Andriy Fedorov <[hidden email]> wrote:

> Aaron,
>
> The center of rotation is always RAS space origin (0,0,0), not image
> origin. (0,0,0) is the origin of Slicer "universe".
>
> Andrey
>
>
> On Tue, Mar 1, 2011 at 16:29, Aaron Ward <[hidden email]> wrote:
>> Hi Dominik,
>>
>> Thanks for the reply.  What I find confusing is that the behaviour I
>> described below is observed even when no image is loaded, so there is
>> no image origin to speak of.
>>
>> Aaron
>>
>> On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier <[hidden email]> wrote:
>>> Hi Aaron
>>>
>>> I've grappled with this also. The reason I think is that rotations are relative to the image origin, which is not included in what is displayed in the transforms module, so combined rotations & translations will show some differences, although they do the same thing.
>>>
>>> Dominik
>>>
>>> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>>>
>>>> Hi Steve,
>>>>
>>>> Thanks for the quick reply!  Here is a specific example.  If I load
>>>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>>>> choosing "Load Transforms" in the transforms module:
>>>>
>>>> #Insight Transform File V1.0
>>>> # Transform 0
>>>> Transform: AffineTransform_double_3_3
>>>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>>>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>>>> FixedParameters: 0 0 0
>>>>
>>>> I see the following matrix in the Transforms window:
>>>>
>>>> 0.996918 -0.078459 -0.000000 6.899965
>>>> 0.068016 0.864225 -0.498488 -95.999726
>>>> 0.039111 0.496951 0.866896 266.299559
>>>> -0.000000 0.000000 -0.000000 1.000000
>>>>
>>>> It looks like the entries corresponding to the translation do not
>>>> match those in the .tfm file.
>>>>
>>>> Thanks,
>>>> Aaron
>>>>
>>>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper <[hidden email]> wrote:
>>>>> Hi Aaron -
>>>>>
>>>>> Could you be more specific about what is different?
>>>>>
>>>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>>>
>>>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>>>
>>>>> -Steve
>>>>>
>>>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>>>> Transforms module (by manipulating the slider bars for translation and
>>>>>> rotation) and then save the transform to disk, the numbers in the .tfm
>>>>>> file do not represent the same matrix as shown in the Slicer interface
>>>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>>>
>>>>>> Thanks,
>>>>>> Aaron Ward
>>>>>> _______________________________________________
>>>>>> slicer-users mailing list
>>>>>> [hidden email]
>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>> To unsubscribe: send email to
>>>>>> [hidden email] with unsubscribe as the
>>>>>> subject
>>>>>
>>>> _______________________________________________
>>>> slicer-users mailing list
>>>> [hidden email]
>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>>
>>>
>>
>>
>>
>> --
>> Aaron D. Ward, PhD
>> Cancer Care Ontario Research Chair in Cancer Imaging
>> Assistant Professor, Medical Biophysics & Biomedical Engineering
>> Schulich School of Medicine and Dentistry
>> The University of Western Ontario
>>
>> Co-Principal Investigator, Imaging Research Laboratory
>> Gerald C. Baines Centre for Translational Cancer Research
>> Room A3-121, London Regional Cancer Program
>> London Health Sciences Centre
>> 790 Commissioners Road East
>> London, ON, Canada  N6A 4L6
>>
>> Tel: 519-685-8500 x 56846
>> Fax: 519-685-8658
>> E-mail: [hidden email]
>> _______________________________________________
>> slicer-users mailing list
>> [hidden email]
>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>
>
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Dominik Meier
You may be looking at the inverse. Because Slicer does backward mapping for instant display some transforms are shown as inverses.

Dominik

On Mar 1, 2011, at 4:49 PM, Aaron Ward wrote:

> Hi Andrey,
>
> Thanks for your help.
>
> I should probably clarify my question.  There is no image involved.
> If I do the following:
>
> 1. Launch 3D Slicer.
> 2. Create a transform.
> 3. Adjust it by adjusting the 6 slider bars in the Transforms module.
> 4. Save the transform as a .tfm file.
> 5. Inspect the contents of the .tfm file in a text editor, and compare
> them to what is shown in the 4x4 matrix in the Transforms module.
>
> In step 5, the contents of the .tfm file and what is displayed in the
> Transforms module do not match.
>
> There is no image, and no image origin involved anywhere in the above process.
>
> Any insights would be appreciated as to why 3D Slicer would save
> different a different matrix to the .tfm file than that shown in the
> Transforms window.
>
> Thanks,
> Aaron
>
> On Tue, Mar 1, 2011 at 4:43 PM, Andriy Fedorov <[hidden email]> wrote:
>> Aaron,
>>
>> The center of rotation is always RAS space origin (0,0,0), not image
>> origin. (0,0,0) is the origin of Slicer "universe".
>>
>> Andrey
>>
>>
>> On Tue, Mar 1, 2011 at 16:29, Aaron Ward <[hidden email]> wrote:
>>> Hi Dominik,
>>>
>>> Thanks for the reply.  What I find confusing is that the behaviour I
>>> described below is observed even when no image is loaded, so there is
>>> no image origin to speak of.
>>>
>>> Aaron
>>>
>>> On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier <[hidden email]> wrote:
>>>> Hi Aaron
>>>>
>>>> I've grappled with this also. The reason I think is that rotations are relative to the image origin, which is not included in what is displayed in the transforms module, so combined rotations & translations will show some differences, although they do the same thing.
>>>>
>>>> Dominik
>>>>
>>>> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>>>>
>>>>> Hi Steve,
>>>>>
>>>>> Thanks for the quick reply!  Here is a specific example.  If I load
>>>>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>>>>> choosing "Load Transforms" in the transforms module:
>>>>>
>>>>> #Insight Transform File V1.0
>>>>> # Transform 0
>>>>> Transform: AffineTransform_double_3_3
>>>>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>>>>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>>>>> FixedParameters: 0 0 0
>>>>>
>>>>> I see the following matrix in the Transforms window:
>>>>>
>>>>> 0.996918 -0.078459 -0.000000 6.899965
>>>>> 0.068016 0.864225 -0.498488 -95.999726
>>>>> 0.039111 0.496951 0.866896 266.299559
>>>>> -0.000000 0.000000 -0.000000 1.000000
>>>>>
>>>>> It looks like the entries corresponding to the translation do not
>>>>> match those in the .tfm file.
>>>>>
>>>>> Thanks,
>>>>> Aaron
>>>>>
>>>>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper <[hidden email]> wrote:
>>>>>> Hi Aaron -
>>>>>>
>>>>>> Could you be more specific about what is different?
>>>>>>
>>>>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>>>>
>>>>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>>>>
>>>>>> -Steve
>>>>>>
>>>>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>>>>> Transforms module (by manipulating the slider bars for translation and
>>>>>>> rotation) and then save the transform to disk, the numbers in the .tfm
>>>>>>> file do not represent the same matrix as shown in the Slicer interface
>>>>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Aaron Ward
>>>>>>> _______________________________________________
>>>>>>> slicer-users mailing list
>>>>>>> [hidden email]
>>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>>> To unsubscribe: send email to
>>>>>>> [hidden email] with unsubscribe as the
>>>>>>> subject
>>>>>>
>>>>> _______________________________________________
>>>>> slicer-users mailing list
>>>>> [hidden email]
>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Aaron D. Ward, PhD
>>> Cancer Care Ontario Research Chair in Cancer Imaging
>>> Assistant Professor, Medical Biophysics & Biomedical Engineering
>>> Schulich School of Medicine and Dentistry
>>> The University of Western Ontario
>>>
>>> Co-Principal Investigator, Imaging Research Laboratory
>>> Gerald C. Baines Centre for Translational Cancer Research
>>> Room A3-121, London Regional Cancer Program
>>> London Health Sciences Centre
>>> 790 Commissioners Road East
>>> London, ON, Canada  N6A 4L6
>>>
>>> Tel: 519-685-8500 x 56846
>>> Fax: 519-685-8658
>>> E-mail: [hidden email]
>>> _______________________________________________
>>> slicer-users mailing list
>>> [hidden email]
>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>>
>>

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

pieper
Administrator
In reply to this post by Aaron Ward
Hi Aaron -

I can explain this - first, let me suggest a 'step 6' which is to
re-load the .tfm back into slicer and confirm you have the same data as
you saved from slicer.  (you should).

The explanation of this is kind of buried in the details of transforms.
  I've pasted the relevant code below for people who are interested in
the implementation, but the issue relates to the difference between
slicer which uses a "computer graphics" view of the world and itk which
uses an "image processing" view of the world.

By this I mean that in slicer you have a matrix hierarchy and you think
in terms of moving an object from one spot to another - so a transform
that has a positive "superior" value wrapped around a volume moves the
volume up in patient space.

But ITK thinks of transformations in terms of mapping backwards from the
display space back to the original image.  Imagine if you are stepping
sequentially through the output pixels then ITK wants to know the
transform that takes you back to the input pixels that it needs to use
to calculate the output.

This is why image processing is sometimes referred to as computer
graphics' "evil twin" (actually, I made up that "evil twin" part, but I
think it fits...).

This modeling vs. resampling issue is in addition to the LPS/RAS issue,
which also complicates things.

Hope that all makes sense,
Steve



int vtkMRMLTransformStorageNode::WriteData(vtkMRMLNode *refNode)

>     // Convert from RAS (Slicer) to LPS (ITK)
>     //
>     // Tlps = ras2lps * Tras * lps2ras
>     //
>     vtkSmartPointer<vtkMatrix4x4> vtkmat = vtkSmartPointer<vtkMatrix4x4>::New();
>
>     vtkMatrix4x4::Multiply4x4(ras2lps, mat2parent, vtkmat);
>     vtkMatrix4x4::Multiply4x4(vtkmat, lps2ras, vtkmat);
>
>     // Convert the sense of the transform (from a Slicer modeling
>     // transform to an ITK resampling transform)
>     //
>     vtkmat->Invert();
>
>     typedef AffineTransformType::MatrixType MatrixType;
>     typedef AffineTransformType::OutputVectorType OffsetType;
>



On 03/01/2011 04:49 PM, Aaron Ward wrote:

> Hi Andrey,
>
> Thanks for your help.
>
> I should probably clarify my question.  There is no image involved.
> If I do the following:
>
> 1. Launch 3D Slicer.
> 2. Create a transform.
> 3. Adjust it by adjusting the 6 slider bars in the Transforms module.
> 4. Save the transform as a .tfm file.
> 5. Inspect the contents of the .tfm file in a text editor, and compare
> them to what is shown in the 4x4 matrix in the Transforms module.
>
> In step 5, the contents of the .tfm file and what is displayed in the
> Transforms module do not match.
>
> There is no image, and no image origin involved anywhere in the above process.
>
> Any insights would be appreciated as to why 3D Slicer would save
> different a different matrix to the .tfm file than that shown in the
> Transforms window.
>
> Thanks,
> Aaron
>
> On Tue, Mar 1, 2011 at 4:43 PM, Andriy Fedorov<[hidden email]>  wrote:
>> Aaron,
>>
>> The center of rotation is always RAS space origin (0,0,0), not image
>> origin. (0,0,0) is the origin of Slicer "universe".
>>
>> Andrey
>>
>>
>> On Tue, Mar 1, 2011 at 16:29, Aaron Ward<[hidden email]>  wrote:
>>> Hi Dominik,
>>>
>>> Thanks for the reply.  What I find confusing is that the behaviour I
>>> described below is observed even when no image is loaded, so there is
>>> no image origin to speak of.
>>>
>>> Aaron
>>>
>>> On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier<[hidden email]>  wrote:
>>>> Hi Aaron
>>>>
>>>> I've grappled with this also. The reason I think is that rotations are relative to the image origin, which is not included in what is displayed in the transforms module, so combined rotations&  translations will show some differences, although they do the same thing.
>>>>
>>>> Dominik
>>>>
>>>> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>>>>
>>>>> Hi Steve,
>>>>>
>>>>> Thanks for the quick reply!  Here is a specific example.  If I load
>>>>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>>>>> choosing "Load Transforms" in the transforms module:
>>>>>
>>>>> #Insight Transform File V1.0
>>>>> # Transform 0
>>>>> Transform: AffineTransform_double_3_3
>>>>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>>>>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>>>>> FixedParameters: 0 0 0
>>>>>
>>>>> I see the following matrix in the Transforms window:
>>>>>
>>>>> 0.996918 -0.078459 -0.000000 6.899965
>>>>> 0.068016 0.864225 -0.498488 -95.999726
>>>>> 0.039111 0.496951 0.866896 266.299559
>>>>> -0.000000 0.000000 -0.000000 1.000000
>>>>>
>>>>> It looks like the entries corresponding to the translation do not
>>>>> match those in the .tfm file.
>>>>>
>>>>> Thanks,
>>>>> Aaron
>>>>>
>>>>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper<[hidden email]>  wrote:
>>>>>> Hi Aaron -
>>>>>>
>>>>>> Could you be more specific about what is different?
>>>>>>
>>>>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>>>>
>>>>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>>>>
>>>>>> -Steve
>>>>>>
>>>>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>>>>> Transforms module (by manipulating the slider bars for translation and
>>>>>>> rotation) and then save the transform to disk, the numbers in the .tfm
>>>>>>> file do not represent the same matrix as shown in the Slicer interface
>>>>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Aaron Ward
>>>>>>> _______________________________________________
>>>>>>> slicer-users mailing list
>>>>>>> [hidden email]
>>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>>> To unsubscribe: send email to
>>>>>>> [hidden email] with unsubscribe as the
>>>>>>> subject
>>>>>>
>>>>> _______________________________________________
>>>>> slicer-users mailing list
>>>>> [hidden email]
>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Aaron D. Ward, PhD
>>> Cancer Care Ontario Research Chair in Cancer Imaging
>>> Assistant Professor, Medical Biophysics&  Biomedical Engineering
>>> Schulich School of Medicine and Dentistry
>>> The University of Western Ontario
>>>
>>> Co-Principal Investigator, Imaging Research Laboratory
>>> Gerald C. Baines Centre for Translational Cancer Research
>>> Room A3-121, London Regional Cancer Program
>>> London Health Sciences Centre
>>> 790 Commissioners Road East
>>> London, ON, Canada  N6A 4L6
>>>
>>> Tel: 519-685-8500 x 56846
>>> Fax: 519-685-8658
>>> E-mail: [hidden email]
>>> _______________________________________________
>>> slicer-users mailing list
>>> [hidden email]
>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>>
>>
> _______________________________________________
> slicer-users mailing list
> [hidden email]
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Aaron Ward
Hi Steve,

Thank you for this detailed explanation - this is very helpful!

My use case is as follows:

1. Load two images into Slicer.
2. Create a Transform, and connect one (moving) image to it.
3. Manually register the moving image to the fixed image by manually
manipulating the slider bars of the Transform.
4. Save the transform to disk as a .tfm file.
5. Transform many 3D volumes according to the transform I defined in
step 3 in a batch using ITK code I have written for this purpose.

If I just read the .tfm file output from step 4 into my ITK code in
step 5 directly, I will not get the intended results, right?

Thanks,
Aaron

On Tue, Mar 1, 2011 at 5:08 PM, Steve Pieper <[hidden email]> wrote:

> Hi Aaron -
>
> I can explain this - first, let me suggest a 'step 6' which is to re-load
> the .tfm back into slicer and confirm you have the same data as you saved
> from slicer.  (you should).
>
> The explanation of this is kind of buried in the details of transforms.
>  I've pasted the relevant code below for people who are interested in the
> implementation, but the issue relates to the difference between slicer which
> uses a "computer graphics" view of the world and itk which uses an "image
> processing" view of the world.
>
> By this I mean that in slicer you have a matrix hierarchy and you think in
> terms of moving an object from one spot to another - so a transform that has
> a positive "superior" value wrapped around a volume moves the volume up in
> patient space.
>
> But ITK thinks of transformations in terms of mapping backwards from the
> display space back to the original image.  Imagine if you are stepping
> sequentially through the output pixels then ITK wants to know the transform
> that takes you back to the input pixels that it needs to use to calculate
> the output.
>
> This is why image processing is sometimes referred to as computer graphics'
> "evil twin" (actually, I made up that "evil twin" part, but I think it
> fits...).
>
> This modeling vs. resampling issue is in addition to the LPS/RAS issue,
> which also complicates things.
>
> Hope that all makes sense,
> Steve
>
>
>
> int vtkMRMLTransformStorageNode::WriteData(vtkMRMLNode *refNode)
>
>>    // Convert from RAS (Slicer) to LPS (ITK)
>>    //
>>    // Tlps = ras2lps * Tras * lps2ras
>>    //
>>    vtkSmartPointer<vtkMatrix4x4> vtkmat =
>> vtkSmartPointer<vtkMatrix4x4>::New();
>>
>>    vtkMatrix4x4::Multiply4x4(ras2lps, mat2parent, vtkmat);
>>    vtkMatrix4x4::Multiply4x4(vtkmat, lps2ras, vtkmat);
>>
>>    // Convert the sense of the transform (from a Slicer modeling
>>    // transform to an ITK resampling transform)
>>    //
>>    vtkmat->Invert();
>>
>>    typedef AffineTransformType::MatrixType MatrixType;
>>    typedef AffineTransformType::OutputVectorType OffsetType;
>>
>
>
>
> On 03/01/2011 04:49 PM, Aaron Ward wrote:
>>
>> Hi Andrey,
>>
>> Thanks for your help.
>>
>> I should probably clarify my question.  There is no image involved.
>> If I do the following:
>>
>> 1. Launch 3D Slicer.
>> 2. Create a transform.
>> 3. Adjust it by adjusting the 6 slider bars in the Transforms module.
>> 4. Save the transform as a .tfm file.
>> 5. Inspect the contents of the .tfm file in a text editor, and compare
>> them to what is shown in the 4x4 matrix in the Transforms module.
>>
>> In step 5, the contents of the .tfm file and what is displayed in the
>> Transforms module do not match.
>>
>> There is no image, and no image origin involved anywhere in the above
>> process.
>>
>> Any insights would be appreciated as to why 3D Slicer would save
>> different a different matrix to the .tfm file than that shown in the
>> Transforms window.
>>
>> Thanks,
>> Aaron
>>
>> On Tue, Mar 1, 2011 at 4:43 PM, Andriy Fedorov<[hidden email]>
>>  wrote:
>>>
>>> Aaron,
>>>
>>> The center of rotation is always RAS space origin (0,0,0), not image
>>> origin. (0,0,0) is the origin of Slicer "universe".
>>>
>>> Andrey
>>>
>>>
>>> On Tue, Mar 1, 2011 at 16:29, Aaron Ward<[hidden email]>  wrote:
>>>>
>>>> Hi Dominik,
>>>>
>>>> Thanks for the reply.  What I find confusing is that the behaviour I
>>>> described below is observed even when no image is loaded, so there is
>>>> no image origin to speak of.
>>>>
>>>> Aaron
>>>>
>>>> On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier<[hidden email]>
>>>>  wrote:
>>>>>
>>>>> Hi Aaron
>>>>>
>>>>> I've grappled with this also. The reason I think is that rotations are
>>>>> relative to the image origin, which is not included in what is displayed in
>>>>> the transforms module, so combined rotations&  translations will show some
>>>>> differences, although they do the same thing.
>>>>>
>>>>> Dominik
>>>>>
>>>>> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>>>>>
>>>>>> Hi Steve,
>>>>>>
>>>>>> Thanks for the quick reply!  Here is a specific example.  If I load
>>>>>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>>>>>> choosing "Load Transforms" in the transforms module:
>>>>>>
>>>>>> #Insight Transform File V1.0
>>>>>> # Transform 0
>>>>>> Transform: AffineTransform_double_3_3
>>>>>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>>>>>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>>>>>> FixedParameters: 0 0 0
>>>>>>
>>>>>> I see the following matrix in the Transforms window:
>>>>>>
>>>>>> 0.996918 -0.078459 -0.000000 6.899965
>>>>>> 0.068016 0.864225 -0.498488 -95.999726
>>>>>> 0.039111 0.496951 0.866896 266.299559
>>>>>> -0.000000 0.000000 -0.000000 1.000000
>>>>>>
>>>>>> It looks like the entries corresponding to the translation do not
>>>>>> match those in the .tfm file.
>>>>>>
>>>>>> Thanks,
>>>>>> Aaron
>>>>>>
>>>>>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper<[hidden email]>
>>>>>>  wrote:
>>>>>>>
>>>>>>> Hi Aaron -
>>>>>>>
>>>>>>> Could you be more specific about what is different?
>>>>>>>
>>>>>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>>>>>
>>>>>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>>>>>
>>>>>>> -Steve
>>>>>>>
>>>>>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>>>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>>>>>> Transforms module (by manipulating the slider bars for translation
>>>>>>>> and
>>>>>>>> rotation) and then save the transform to disk, the numbers in the
>>>>>>>> .tfm
>>>>>>>> file do not represent the same matrix as shown in the Slicer
>>>>>>>> interface
>>>>>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Aaron Ward
>>>>>>>> _______________________________________________
>>>>>>>> slicer-users mailing list
>>>>>>>> [hidden email]
>>>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>>>> To unsubscribe: send email to
>>>>>>>> [hidden email] with unsubscribe as
>>>>>>>> the
>>>>>>>> subject
>>>>>>>
>>>>>> _______________________________________________
>>>>>> slicer-users mailing list
>>>>>> [hidden email]
>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>> To unsubscribe: send email to
>>>>>> [hidden email] with unsubscribe as the
>>>>>> subject
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Aaron D. Ward, PhD
>>>> Cancer Care Ontario Research Chair in Cancer Imaging
>>>> Assistant Professor, Medical Biophysics&  Biomedical Engineering
>>>> Schulich School of Medicine and Dentistry
>>>> The University of Western Ontario
>>>>
>>>> Co-Principal Investigator, Imaging Research Laboratory
>>>> Gerald C. Baines Centre for Translational Cancer Research
>>>> Room A3-121, London Regional Cancer Program
>>>> London Health Sciences Centre
>>>> 790 Commissioners Road East
>>>> London, ON, Canada  N6A 4L6
>>>>
>>>> Tel: 519-685-8500 x 56846
>>>> Fax: 519-685-8658
>>>> E-mail: [hidden email]
>>>> _______________________________________________
>>>> slicer-users mailing list
>>>> [hidden email]
>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>> To unsubscribe: send email to
>>>> [hidden email] with unsubscribe as the
>>>> subject
>>>>
>>>
>> _______________________________________________
>> slicer-users mailing list
>> [hidden email]
>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>> To unsubscribe: send email to
>> [hidden email] with unsubscribe as the
>> subject
>



--
Aaron D. Ward, PhD
Cancer Care Ontario Research Chair in Cancer Imaging
Assistant Professor, Medical Biophysics & Biomedical Engineering
Schulich School of Medicine and Dentistry
The University of Western Ontario

Co-Principal Investigator, Imaging Research Laboratory
Gerald C. Baines Centre for Translational Cancer Research
Room A3-121, London Regional Cancer Program
London Health Sciences Centre
790 Commissioners Road East
London, ON, Canada  N6A 4L6

Tel: 519-685-8500 x 56846
Fax: 519-685-8658
E-mail: [hidden email]
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Jim Miller
In reply to this post by pieper
As Steve points out, there are a number of things going on that make it tricky to map transforms in the widget to transforms in the files.

The "what's"....

1. The transform represented in the widget is in RAS.
2. The transform represented in the tfm file is in LPS.
3. The transform represented in the file is the inverse of the transform in the widget (plus it has the LPS/RAS conversion applied).
4. The order of the parameters in the tfm are the elements of the upper 3x3 of the transform displayed in the widget followed by the elements in the last column of the widget.

Transform from the widget:
--> c = [0.996918 -0.078459 -0.000000 6.899965; 0.068016 0.864225 -0.498488 -95.999726; 0.039111 0.496951 0.866896 266.299559; 0.0 0.000000 -0.000000 1.000000]
c =
    0.9969   -0.0785         0    6.9000
    0.0680    0.8642   -0.4985  -95.9997
    0.0391    0.4970    0.8669  266.2996
         0         0         0    1.0000

Take the inverse
--> inv(c)
ans =
    0.9969    0.0680    0.0391  -10.7644
   -0.0785    0.8642    0.4970  -48.8313
   -0.0000   -0.4985    0.8669 -278.7091
         0         0         0    1.0000

LPS to RAS conversion will  take you all the way to what is the file. (I don't have that transform on the tip of my tongue.) But as the code snippet Steve included you would pre and post multiply inv(c) by a pair of matrices.

The "why's" are in Steve's reply.....




On Tue, Mar 1, 2011 at 5:08 PM, Steve Pieper <[hidden email]> wrote:
Hi Aaron -

I can explain this - first, let me suggest a 'step 6' which is to
re-load the .tfm back into slicer and confirm you have the same data as
you saved from slicer.  (you should).

The explanation of this is kind of buried in the details of transforms.
 I've pasted the relevant code below for people who are interested in
the implementation, but the issue relates to the difference between
slicer which uses a "computer graphics" view of the world and itk which
uses an "image processing" view of the world.

By this I mean that in slicer you have a matrix hierarchy and you think
in terms of moving an object from one spot to another - so a transform
that has a positive "superior" value wrapped around a volume moves the
volume up in patient space.

But ITK thinks of transformations in terms of mapping backwards from the
display space back to the original image.  Imagine if you are stepping
sequentially through the output pixels then ITK wants to know the
transform that takes you back to the input pixels that it needs to use
to calculate the output.

This is why image processing is sometimes referred to as computer
graphics' "evil twin" (actually, I made up that "evil twin" part, but I
think it fits...).

This modeling vs. resampling issue is in addition to the LPS/RAS issue,
which also complicates things.

Hope that all makes sense,
Steve



int vtkMRMLTransformStorageNode::WriteData(vtkMRMLNode *refNode)

>     // Convert from RAS (Slicer) to LPS (ITK)
>     //
>     // Tlps = ras2lps * Tras * lps2ras
>     //
>     vtkSmartPointer<vtkMatrix4x4> vtkmat = vtkSmartPointer<vtkMatrix4x4>::New();
>
>     vtkMatrix4x4::Multiply4x4(ras2lps, mat2parent, vtkmat);
>     vtkMatrix4x4::Multiply4x4(vtkmat, lps2ras, vtkmat);
>
>     // Convert the sense of the transform (from a Slicer modeling
>     // transform to an ITK resampling transform)
>     //
>     vtkmat->Invert();
>
>     typedef AffineTransformType::MatrixType MatrixType;
>     typedef AffineTransformType::OutputVectorType OffsetType;
>



On 03/01/2011 04:49 PM, Aaron Ward wrote:
> Hi Andrey,
>
> Thanks for your help.
>
> I should probably clarify my question.  There is no image involved.
> If I do the following:
>
> 1. Launch 3D Slicer.
> 2. Create a transform.
> 3. Adjust it by adjusting the 6 slider bars in the Transforms module.
> 4. Save the transform as a .tfm file.
> 5. Inspect the contents of the .tfm file in a text editor, and compare
> them to what is shown in the 4x4 matrix in the Transforms module.
>
> In step 5, the contents of the .tfm file and what is displayed in the
> Transforms module do not match.
>
> There is no image, and no image origin involved anywhere in the above process.
>
> Any insights would be appreciated as to why 3D Slicer would save
> different a different matrix to the .tfm file than that shown in the
> Transforms window.
>
> Thanks,
> Aaron
>
> On Tue, Mar 1, 2011 at 4:43 PM, Andriy Fedorov<[hidden email]>  wrote:
>> Aaron,
>>
>> The center of rotation is always RAS space origin (0,0,0), not image
>> origin. (0,0,0) is the origin of Slicer "universe".
>>
>> Andrey
>>
>>
>> On Tue, Mar 1, 2011 at 16:29, Aaron Ward<[hidden email]>  wrote:
>>> Hi Dominik,
>>>
>>> Thanks for the reply.  What I find confusing is that the behaviour I
>>> described below is observed even when no image is loaded, so there is
>>> no image origin to speak of.
>>>
>>> Aaron
>>>
>>> On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier<[hidden email]>  wrote:
>>>> Hi Aaron
>>>>
>>>> I've grappled with this also. The reason I think is that rotations are relative to the image origin, which is not included in what is displayed in the transforms module, so combined rotations&  translations will show some differences, although they do the same thing.
>>>>
>>>> Dominik
>>>>
>>>> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>>>>
>>>>> Hi Steve,
>>>>>
>>>>> Thanks for the quick reply!  Here is a specific example.  If I load
>>>>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>>>>> choosing "Load Transforms" in the transforms module:
>>>>>
>>>>> #Insight Transform File V1.0
>>>>> # Transform 0
>>>>> Transform: AffineTransform_double_3_3
>>>>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>>>>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>>>>> FixedParameters: 0 0 0
>>>>>
>>>>> I see the following matrix in the Transforms window:
>>>>>
>>>>> 0.996918 -0.078459 -0.000000 6.899965
>>>>> 0.068016 0.864225 -0.498488 -95.999726
>>>>> 0.039111 0.496951 0.866896 266.299559
>>>>> -0.000000 0.000000 -0.000000 1.000000
>>>>>
>>>>> It looks like the entries corresponding to the translation do not
>>>>> match those in the .tfm file.
>>>>>
>>>>> Thanks,
>>>>> Aaron
>>>>>
>>>>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper<[hidden email]>  wrote:
>>>>>> Hi Aaron -
>>>>>>
>>>>>> Could you be more specific about what is different?
>>>>>>
>>>>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>>>>
>>>>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>>>>
>>>>>> -Steve
>>>>>>
>>>>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>>>>> Transforms module (by manipulating the slider bars for translation and
>>>>>>> rotation) and then save the transform to disk, the numbers in the .tfm
>>>>>>> file do not represent the same matrix as shown in the Slicer interface
>>>>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Aaron Ward
>>>>>>> _______________________________________________
>>>>>>> slicer-users mailing list
>>>>>>> [hidden email]
>>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>>> To unsubscribe: send email to
>>>>>>> [hidden email] with unsubscribe as the
>>>>>>> subject
>>>>>>
>>>>> _______________________________________________
>>>>> slicer-users mailing list
>>>>> [hidden email]
>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Aaron D. Ward, PhD
>>> Cancer Care Ontario Research Chair in Cancer Imaging
>>> Assistant Professor, Medical Biophysics&  Biomedical Engineering
>>> Schulich School of Medicine and Dentistry
>>> The University of Western Ontario
>>>
>>> Co-Principal Investigator, Imaging Research Laboratory
>>> Gerald C. Baines Centre for Translational Cancer Research
>>> Room A3-121, London Regional Cancer Program
>>> London Health Sciences Centre
>>> 790 Commissioners Road East
>>> London, ON, Canada  N6A 4L6
>>>
>>> Tel: 519-685-8500 x 56846
>>> Fax: 519-685-8658
>>> E-mail: [hidden email]
>>> _______________________________________________
>>> slicer-users mailing list
>>> [hidden email]
>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
>>>
>>
> _______________________________________________
> slicer-users mailing list
> [hidden email]
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject


_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

pieper
Administrator
In reply to this post by Aaron Ward
Yes, I think that's the right ITK transform - you could compare what you
do with what Francois does in the Resample Scarar/Vector/Diffusion
module (as Applications/CLI/ResampleVolume2.cxx).

The goal has always to keep the ITK-based modules as close to native ITK
as possible.

Best,
steve

On 03/01/2011 05:14 PM, Aaron Ward wrote:

> Hi Steve,
>
> Thank you for this detailed explanation - this is very helpful!
>
> My use case is as follows:
>
> 1. Load two images into Slicer.
> 2. Create a Transform, and connect one (moving) image to it.
> 3. Manually register the moving image to the fixed image by manually
> manipulating the slider bars of the Transform.
> 4. Save the transform to disk as a .tfm file.
> 5. Transform many 3D volumes according to the transform I defined in
> step 3 in a batch using ITK code I have written for this purpose.
>
> If I just read the .tfm file output from step 4 into my ITK code in
> step 5 directly, I will not get the intended results, right?
>
> Thanks,
> Aaron
>
> On Tue, Mar 1, 2011 at 5:08 PM, Steve Pieper<[hidden email]>  wrote:
>> Hi Aaron -
>>
>> I can explain this - first, let me suggest a 'step 6' which is to re-load
>> the .tfm back into slicer and confirm you have the same data as you saved
>> from slicer.  (you should).
>>
>> The explanation of this is kind of buried in the details of transforms.
>>   I've pasted the relevant code below for people who are interested in the
>> implementation, but the issue relates to the difference between slicer which
>> uses a "computer graphics" view of the world and itk which uses an "image
>> processing" view of the world.
>>
>> By this I mean that in slicer you have a matrix hierarchy and you think in
>> terms of moving an object from one spot to another - so a transform that has
>> a positive "superior" value wrapped around a volume moves the volume up in
>> patient space.
>>
>> But ITK thinks of transformations in terms of mapping backwards from the
>> display space back to the original image.  Imagine if you are stepping
>> sequentially through the output pixels then ITK wants to know the transform
>> that takes you back to the input pixels that it needs to use to calculate
>> the output.
>>
>> This is why image processing is sometimes referred to as computer graphics'
>> "evil twin" (actually, I made up that "evil twin" part, but I think it
>> fits...).
>>
>> This modeling vs. resampling issue is in addition to the LPS/RAS issue,
>> which also complicates things.
>>
>> Hope that all makes sense,
>> Steve
>>
>>
>>
>> int vtkMRMLTransformStorageNode::WriteData(vtkMRMLNode *refNode)
>>
>>>     // Convert from RAS (Slicer) to LPS (ITK)
>>>     //
>>>     // Tlps = ras2lps * Tras * lps2ras
>>>     //
>>>     vtkSmartPointer<vtkMatrix4x4>  vtkmat =
>>> vtkSmartPointer<vtkMatrix4x4>::New();
>>>
>>>     vtkMatrix4x4::Multiply4x4(ras2lps, mat2parent, vtkmat);
>>>     vtkMatrix4x4::Multiply4x4(vtkmat, lps2ras, vtkmat);
>>>
>>>     // Convert the sense of the transform (from a Slicer modeling
>>>     // transform to an ITK resampling transform)
>>>     //
>>>     vtkmat->Invert();
>>>
>>>     typedef AffineTransformType::MatrixType MatrixType;
>>>     typedef AffineTransformType::OutputVectorType OffsetType;
>>>
>>
>>
>>
>> On 03/01/2011 04:49 PM, Aaron Ward wrote:
>>>
>>> Hi Andrey,
>>>
>>> Thanks for your help.
>>>
>>> I should probably clarify my question.  There is no image involved.
>>> If I do the following:
>>>
>>> 1. Launch 3D Slicer.
>>> 2. Create a transform.
>>> 3. Adjust it by adjusting the 6 slider bars in the Transforms module.
>>> 4. Save the transform as a .tfm file.
>>> 5. Inspect the contents of the .tfm file in a text editor, and compare
>>> them to what is shown in the 4x4 matrix in the Transforms module.
>>>
>>> In step 5, the contents of the .tfm file and what is displayed in the
>>> Transforms module do not match.
>>>
>>> There is no image, and no image origin involved anywhere in the above
>>> process.
>>>
>>> Any insights would be appreciated as to why 3D Slicer would save
>>> different a different matrix to the .tfm file than that shown in the
>>> Transforms window.
>>>
>>> Thanks,
>>> Aaron
>>>
>>> On Tue, Mar 1, 2011 at 4:43 PM, Andriy Fedorov<[hidden email]>
>>>   wrote:
>>>>
>>>> Aaron,
>>>>
>>>> The center of rotation is always RAS space origin (0,0,0), not image
>>>> origin. (0,0,0) is the origin of Slicer "universe".
>>>>
>>>> Andrey
>>>>
>>>>
>>>> On Tue, Mar 1, 2011 at 16:29, Aaron Ward<[hidden email]>    wrote:
>>>>>
>>>>> Hi Dominik,
>>>>>
>>>>> Thanks for the reply.  What I find confusing is that the behaviour I
>>>>> described below is observed even when no image is loaded, so there is
>>>>> no image origin to speak of.
>>>>>
>>>>> Aaron
>>>>>
>>>>> On Tue, Mar 1, 2011 at 4:28 PM, Dominik Meier<[hidden email]>
>>>>>   wrote:
>>>>>>
>>>>>> Hi Aaron
>>>>>>
>>>>>> I've grappled with this also. The reason I think is that rotations are
>>>>>> relative to the image origin, which is not included in what is displayed in
>>>>>> the transforms module, so combined rotations&    translations will show some
>>>>>> differences, although they do the same thing.
>>>>>>
>>>>>> Dominik
>>>>>>
>>>>>> On Mar 1, 2011, at 3:01 PM, Aaron Ward wrote:
>>>>>>
>>>>>>> Hi Steve,
>>>>>>>
>>>>>>> Thanks for the quick reply!  Here is a specific example.  If I load
>>>>>>> the the following .tfm file into 3D Slicer Version 3.6.2 1.0 by
>>>>>>> choosing "Load Transforms" in the transforms module:
>>>>>>>
>>>>>>> #Insight Transform File V1.0
>>>>>>> # Transform 0
>>>>>>> Transform: AffineTransform_double_3_3
>>>>>>> Parameters: 0.996917 0.0680159 -0.0391109 -0.0784591 0.864224
>>>>>>> -0.496951 -6.93889e-018 0.498488 0.866897 10.7644 48.8312 -278.709
>>>>>>> FixedParameters: 0 0 0
>>>>>>>
>>>>>>> I see the following matrix in the Transforms window:
>>>>>>>
>>>>>>> 0.996918 -0.078459 -0.000000 6.899965
>>>>>>> 0.068016 0.864225 -0.498488 -95.999726
>>>>>>> 0.039111 0.496951 0.866896 266.299559
>>>>>>> -0.000000 0.000000 -0.000000 1.000000
>>>>>>>
>>>>>>> It looks like the entries corresponding to the translation do not
>>>>>>> match those in the .tfm file.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Aaron
>>>>>>>
>>>>>>> On Tue, Mar 1, 2011 at 2:39 PM, Steve Pieper<[hidden email]>
>>>>>>>   wrote:
>>>>>>>>
>>>>>>>> Hi Aaron -
>>>>>>>>
>>>>>>>> Could you be more specific about what is different?
>>>>>>>>
>>>>>>>> Perhaps you are seeing the LPS/RAS differences described here:
>>>>>>>>
>>>>>>>>> http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
>>>>>>>>
>>>>>>>> -Steve
>>>>>>>>
>>>>>>>> On 03/01/2011 02:03 PM, Aaron Ward wrote:
>>>>>>>>>
>>>>>>>>> Hello,
>>>>>>>>>
>>>>>>>>> I am using 3D Slicer Version 3.6.2 1.0 (3D Slicer Version 3.6.21.0)
>>>>>>>>> under Windows Server 2007 SP2.  When I create a transform in the
>>>>>>>>> Transforms module (by manipulating the slider bars for translation
>>>>>>>>> and
>>>>>>>>> rotation) and then save the transform to disk, the numbers in the
>>>>>>>>> .tfm
>>>>>>>>> file do not represent the same matrix as shown in the Slicer
>>>>>>>>> interface
>>>>>>>>> when this .tfm file is loaded.  Why does this behaviour occur?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Aaron Ward
>>>>>>>>> _______________________________________________
>>>>>>>>> slicer-users mailing list
>>>>>>>>> [hidden email]
>>>>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>>>>> To unsubscribe: send email to
>>>>>>>>> [hidden email] with unsubscribe as
>>>>>>>>> the
>>>>>>>>> subject
>>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> slicer-users mailing list
>>>>>>> [hidden email]
>>>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>>>> To unsubscribe: send email to
>>>>>>> [hidden email] with unsubscribe as the
>>>>>>> subject
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Aaron D. Ward, PhD
>>>>> Cancer Care Ontario Research Chair in Cancer Imaging
>>>>> Assistant Professor, Medical Biophysics&    Biomedical Engineering
>>>>> Schulich School of Medicine and Dentistry
>>>>> The University of Western Ontario
>>>>>
>>>>> Co-Principal Investigator, Imaging Research Laboratory
>>>>> Gerald C. Baines Centre for Translational Cancer Research
>>>>> Room A3-121, London Regional Cancer Program
>>>>> London Health Sciences Centre
>>>>> 790 Commissioners Road East
>>>>> London, ON, Canada  N6A 4L6
>>>>>
>>>>> Tel: 519-685-8500 x 56846
>>>>> Fax: 519-685-8658
>>>>> E-mail: [hidden email]
>>>>> _______________________________________________
>>>>> slicer-users mailing list
>>>>> [hidden email]
>>>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>>>> To unsubscribe: send email to
>>>>> [hidden email] with unsubscribe as the
>>>>> subject
>>>>>
>>>>
>>> _______________________________________________
>>> slicer-users mailing list
>>> [hidden email]
>>> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
>>> To unsubscribe: send email to
>>> [hidden email] with unsubscribe as the
>>> subject
>>
>
>
>
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

bluisier
In reply to this post by pieper
Hi Steve,

What is the content of the "ras2lps" and the "lps2ras" matrices? (for
implementation in my python script)

Thanks in advance

Benoit
Reply | Threaded
Open this post in threaded view
|

Re: Transformation matrices in .tfm files do not match those displayed in Slicer upon load

Steve Pieper
Hi Benoit -

The code snippet is from this code where the content of the matrices are defined by context:

http://viewvc.slicer.org/viewvc.cgi/Slicer3/trunk/Libs/MRML/vtkMRMLTransformStorageNode.cxx?revision=15487&view=markup

HTH,
Steve

On Thu, Apr 26, 2012 at 2:53 AM, bluisier <[hidden email]> wrote:
Hi Steve,

What is the content of the "ras2lps" and the "lps2ras" matrices? (for
implementation in my python script)

Thanks in advance

Benoit

--
View this message in context: http://slicer-users.65878.n3.nabble.com/Transformation-matrices-in-tfm-files-do-not-match-those-displayed-in-Slicer-upon-load-tp2605636p3940416.html
Sent from the slicer-users mailing list archive at Nabble.com.
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject


_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject