Transform in 3D

103 views
Skip to first unread message

Robert Langlois

unread,
Feb 3, 2014, 6:10:23 PM2/3/14
to em...@googlegroups.com
Hi Steven,

I am trying to understand the Transform object. Essentially, I want to rotate a 3D object back to its original position.

I ran the following code:


itrans = trans.inverse()

vol.process_inplace("xform",{"transform":itrans})

To test whether this gives me the transform I want, I did the following:

print trans.get_pre_trans(), '==', itrans.get_pre_trans()

I expected these two translations would be the same except for the sign since they are applied first to the object before the other transforms, e.g. RT not TR.

This is using EMAN 2.1.


Thanks,


Rob


Paul Penczek

unread,
Feb 3, 2014, 7:34:43 PM2/3/14
to em...@googlegroups.com
Hi

Transform operations are defined as matrix multiplications. So, transformation inverse to a given one is obtained by inverting the matrix. Inverse in your example is correct.

Pre and post refer to two conventions: rotation prior or post translation, respectively. This is unrelated to inverting the trasformation.

Much on the subject is written in baldwin&Penczek JSB "transform class in eman2".

Sent from Yahoo Mail for iPhone


From: Robert Langlois <ezrala...@gmail.com>;
To: <em...@googlegroups.com>;
Subject: [EMAN2] Transform in 3D
Sent: Mon, Feb 3, 2014 11:10:23 PM

--
--
----------------------------------------------------------------------------------------------
You received this message because you are subscribed to the Google
Groups "EMAN2" group.
To post to this group, send email to em...@googlegroups.com
To unsubscribe from this group, send email to eman2+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/eman2
 
---
You received this message because you are subscribed to the Google Groups "EMAN2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eman2+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Robert Langlois

unread,
Feb 3, 2014, 8:00:27 PM2/3/14
to em...@googlegroups.com
Hi Pawel, 

Thanks for your quick reply. Given that one can decompose a translation matrix into translation followed by rotation RT (assuming only this simple cause), and given that R'T'  is the decomposition of the inverse of this matrix, then 
T should equal -T'. My intuition is that T moves you to some position and T' moves you back.

What am I missing?

Thanks,

Rob

On Feb 3, 2014, at 7:34 PM, Paul Penczek wrote:

prior

Robert Langlois, Ph.D.
Research Associate, Frank Lab
Columbia University Medical Center
650 W. 168th Street, P&S Black Building 2-221
New York, NY10032
Work: 212 305-9533
Mobile: 847-881-6604
Fax: 212 305-9500
Email: rl2...@columbia.edu

Steven Ludtke

unread,
Feb 3, 2014, 8:19:53 PM2/3/14
to em...@googlegroups.com, em...@googlegroups.com
Hi Rob. In addition to changing sign, upon inversion a pretranslation becomes a posttranslation and vice-versa as well. 

Sent from my iPhone

Paul Penczek

unread,
Feb 3, 2014, 9:01:53 PM2/3/14
to em...@googlegroups.com
I am not sure I understand. Full transformation matrix is 4x4.

Rotation matrix is 3x3.

Inversion of a rotation matrix is indeed the transposition.

In case of pure rotation the inverse or transposition of rotation will result in the object in the original position.

If you are thinking about 3x3 matrices translation cannot be represented by a matrix multiplication.

I believe all tgat is explained in Baldwin paper I mentioned.

From: Robert Langlois <ezrala...@gmail.com>;
To: <em...@googlegroups.com>;
Subject: Re: [EMAN2] Transform in 3D
Sent: Tue, Feb 4, 2014 1:00:27 AM

Steven Ludtke

unread,
Feb 3, 2014, 10:52:16 PM2/3/14
to em...@googlegroups.com
The point being that in the 4x4 matrix which contains both a pre and post translation block, the inverse is the transpose of the 4x4 with both translation vectors also multiplied by -1.  

Think about it this way, if you have an arbitrary rotation followed by a translation by (1,2,0), to invert the transform you would have to begin with a translation of (-1,2,0) followed by the inverse of the rotation matrix. Turning the post-translation into a pre-translation also corresponds to a transpose of 4th row/column, with the -1 included. 

Of course having a full 4x4 is redundant, since any pre-translation can be converted into a post-translation by running the vector through the matrix, and vice-versa, so the internal representation of the matrix in EMAN2/SPARX (and pretty much any other 3-D package) is a 3x4, not a 4x4. Normally the post-translation is stored. If you want the translation as a pre-translation instead, you can ask the library to do the math for you. Just note that this is not a case where there is a separate pre and post translation vector, which you are independently retrieving. When you ask for the post-translation, you are asking for the entire combined translation to be represented as a post-translation (similar for the pre-translation).
----------------------------------------------------------------------------
Steven Ludtke, Ph.D.
Professor, Dept of Biochemistry and Mol. Biol.         (www.bcm.edu/biochem)
Co-Director National Center For Macromolecular Imaging        (ncmi.bcm.edu)
Co-Director CIBR Center                          (www.bcm.edu/research/cibr)
Baylor College of Medicine                             





Message has been deleted

Paul Penczek

unread,
Feb 4, 2014, 12:57:28 PM2/4/14
to em...@googlegroups.com


Come to think about it, there is a simpler way of expressing all that, if we just forget about 3x4 matrices and transformations.

Let R be a rotation matrix and t a translation vector (either 2D or 3D, does not matter), and let x be an arbitrary vector.
The transformation is then written as :

  u = Rx + t

The inverse transformation is obtained by multiplying both sides by R' (either transform or inverse, the same):

 R'u = R'Rx + Rt

since R'R=I

 x = R'u - Rt

so the "backwards' translation is (-Rt) and "backwards" rotation R'.


The difference between pre and post translation is seen from:

  u = Rx + t = R(x + R't)

so postranslation t becomes pretranslation R't.

I hope this is simpler.

Regards,
Pawel.
Message has been deleted

Paul Penczek

unread,
Feb 6, 2014, 5:41:18 PM2/6/14
to em...@googlegroups.com
Hi,

sorry, but I overlooked it.

I lost track of what you wanted to accomplish.  In either case it looks indirect.
Are you sure you looked at:

Pawel


From: Robert Langlois <ezrala...@gmail.com>
To: em...@googlegroups.com
Sent: Wednesday, February 5, 2014 2:29 PM

Subject: Re: [EMAN2] Transform in 3D

Hi Pawel,

The equations made things far clearer.

x = Rx + t
R'u=R'Rx+R't
R'u=x+R't
x = R'u-R't
x = R'(u-t)

So the post translations in the original transform are the pre-translations in the inverse like Steve suggested.

I just wanted to check I was using the code correctly:

      trans = aimg['xform.align3d']   # x = Rx + t
            
            shift = -trans.get_trans()      # This subtracts off the where were the post-translations but now are the pre-translations for the inverse
            trans_shift = EMAN2.Transform()
            trans_shift.set_trans(shift)
            aimg.process_inplace("xform",{"transform":trans_shift})


            #cavg.translate(shift)
            trans.set_trans(0,0,0)           # Set the translations to 0
            itrans = trans.inverse()       # Get the inverse rotation matrix R'
            #cavg.transform(itrans)
            aimg.process_inplace("xform",{"transform":itrans}) # Apply the inverse rotation R'

Thanks,

Rob


--
-- 
Reply all
Reply to author
Forward
0 new messages