Size: 8951
Comment:
|
Size: 9737
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
[[TableOfContents]] | <<TableOfContents>> |
Line 5: | Line 5: |
We use the [http://blake.bcm.edu/eman2/doxygen_html/classEMAN_1_1Transform.html Transform] class for storing/managing Euler angles,translations, scales and x mirroring. At any time a Transform object {{{$$Tr$$}}} defines a group of 4 transformations of a rigid body that are applied in a specific order, namely |
We use the [[http://blake.bcm.edu/eman2/doxygen_html/classEMAN_1_1Transform.html|Transform]] class for storing/managing Euler angles,translations, scales and x mirroring. At any time a Transform object {{{$$Tr$$}}} defines a group of 4 transformations of a rigid body that are applied in a specific order, namely |
Line 20: | Line 18: |
There a three ways to construct a Transform object in Python |
There a four ways to construct a Transform object in Python |
Line 27: | Line 24: |
q = Transform([1,0,0,0,0,1,0,0,0,0,1,0]) # specify the 12 entries of the matrix explicitly, row wise (3 rows of 4) | |
Line 29: | Line 27: |
For more information on default parameters and what happens when some parameters are not set see [#dict_const a more in depth look at the dictionary constructor] |
For more information on default parameters and what happens when some parameters are not set see [[#dict_const|a more in depth look at the dictionary constructor]] |
Line 33: | Line 30: |
Line 41: | Line 37: |
Line 43: | Line 38: |
Line 50: | Line 44: |
Line 52: | Line 45: |
Line 64: | Line 55: |
Line 66: | Line 56: |
Line 75: | Line 64: |
Line 77: | Line 65: |
Line 90: | Line 77: |
For more information the behaviour of set_params see [#set_params a more in depth look at set_params ] |
For more information the behaviour of set_params see [[#set_params|a more in depth look at set_params]] |
Line 94: | Line 80: |
Line 108: | Line 93: |
== Transforming a 3D image == Transforming a 3D image is achieved using a single function call {{{#!python t = Transform() t.set_params({"type":"eman","az":10,"alt":150,"scale":2.0,"mirror":True,"tx":3.4}) t.set_trans( ... ) e = test_image_3d() e.transform(t) }}} You can alternatively use the EMData processing framework, for example: {{{#!python t = Transform() t.set_params({"type":"eman","az":10,"alt":150,"scale":2.0,"mirror":True,"tx":3.4}) t.set_trans( ... ) f = e.process("math.transform",{"transform":t}) # memory efficient e.proceess_inplace("math.transform",{"transform":t}) }}} In fact {{{e.transform(t)}}} actually calls {{{e.proceess_inplace("math.transform",{"transform":t})}}} internally on the C++ side. |
|
Line 114: | Line 119: |
Line 122: | Line 126: |
}}} |
}}} |
Line 126: | Line 128: |
Line 136: | Line 137: |
Line 139: | Line 138: |
Line 148: | Line 146: |
Line 150: | Line 147: |
Line 164: | Line 160: |
[[Anchor(dict_const)]] |
<<Anchor(dict_const)>> |
Line 169: | Line 164: |
Line 171: | Line 165: |
Line 175: | Line 170: |
Line 182: | Line 176: |
Line 188: | Line 181: |
Line 195: | Line 187: |
Line 201: | Line 192: |
[[Anchor(set_params)]] = A more in depth look at set_params = ---- Constructing a Transform with some dictionary is the same as calling set_params on a Transform that is the identity. |
<<Anchor(set_params)>> = A more in depth look at set_params = ---- Constructing a Transform with some dictionary is the same as calling set_params on a Transform that is the identity. |
Line 215: | Line 204: |
Line 218: | Line 206: |
Line 220: | Line 207: |
Line 226: | Line 212: |
== For rotation and translation, setting one is equivalent to setting them all == |
== For rotation and translation, setting one is equivalent to setting them all == |
Contents
What is a Transform?
We use the Transform class for storing/managing Euler angles,translations, scales and x mirroring. At any time a Transform object $$Tr$$ defines a group of 4 transformations of a rigid body that are applied in a specific order, namely
$$ Tr \equiv M T S R $$
Where $$M$$ is a mirroring operation about the x-axis, $$T$$ is a translation, $$S$$ is a uniform, positive, non zero scaling operation and $$R$$ is a rotation. The Transform object stores these transformations internally in a 3x4 matrix, which appears as
$$ Tr = [sMR,M\mathbf{t}]$$
Where $$s$$ is the constant scaling factor, $$M$$ is the identity or the x-mirroring matrix, $$R$$ is a $$3x3$$ rotation matrix and $$\mathbf{t}=(tx,ty,tz)^T$$ is the translation.
The Transform object in Python
Constructing a Transform
There a four ways to construct a Transform object in Python
1 t = Transform() # default constructor, t is the identity
2 t = Transform({"type":"eman","az":10,"alt":150,"scale":2.0,"mirror":True,"tx":3.4}) # construction using a dictionary
3 p = Transform({"type":"eman","az":10,"mirror":True,"tx":3.4}) # construction using a dictionary
4 q = Transform([1,0,0,0,0,1,0,0,0,0,1,0]) # specify the 12 entries of the matrix explicitly, row wise (3 rows of 4)
5 s = Transform(t) # copy construction - s is precisely the same as t
For more information on default parameters and what happens when some parameters are not set see a more in depth look at the dictionary constructor
Setting/getting rotations
Setting/getting scale
Setting/getting mirror
Setting/getting translation
Setting/getting parameters
You can tell a Transform deduce any of its parameters from a dictionary. Similarly you can get the parameters of a Transform as a dictionary
1 t = Transform()
2 t.set_params({"type":"eman","az":10,"alt":150,"scale":2.0,"mirror":True,"tx":3.4})
3 d = t.get_params("eman") # must specify the euler convention
4 s = Transform(d) # s is the same as t
5 d = t.get_params("spider")
6 s = Transform(d) # s is the same as t
7 d = t.get_params("matrix")
8 s = Transform(d) # s is the same as t
For more information the behaviour of set_params see a more in depth look at set_params
A Transform multiplied by a Vec3f
The transformation of a 3D vector $$ v = (v_x,v_y,v_z)^T $$ by a Transform is defined as
$$ Tr \mathbf{v} = [sMR,M\mathbf{t}] (v_x,v_y,v_z,1)^T = sMR\mathbf{v}+ M\mathbf{t} $$
This can be done in Python using the following
Transforming a 3D image
Transforming a 3D image is achieved using a single function call
You can alternatively use the EMData processing framework, for example:
In fact e.transform(t) actually calls e.proceess_inplace("math.transform",{"transform":t}) internally on the C++ side.
2D degenerate use of the Transform object in Python
The Transform object can be used as though it were a 2D transformation matrix. In this case the interface for setting/getting scale and mirror is unchanged. However setting the rotation should be done using the euler type "2d", and there are some accommodations for setting and getting 2d translations and parameters.
Setting/getting 2D rotations
Use the "2d" euler type, and the angle is specified using "alpha"
Setting/getting 2D translation
The interface is more or less identical to the 3D case
Setting/getting 2D parameters
For getting the parameters in 2D form use the following
A Transform multiplied by a Vec2f
The transformation of a 2D vector $$ v_{2D} = (v_x,v_y)^T $$ by a Transform is equivalent to setting the z component of 3D vector to 0. If $$ v = (v_x,v_y,0)^T $$ then the 2D transformation is equivalent to the following,
$$ Tr \mathbf{v_{2D}} = [sMR,M\mathbf{t}] (v_x,v_y,0,1)^T = sMR\mathbf{v}+ M\mathbf{t} $$
and the z component is ignored. Note that the internal implementation is efficient. 2D vector transformation can be done in Python using the following
A more in depth look at the dictionary constructor
The dictionary constructor, which is equivalent to calling the default constructor followed by the set_params function, takes up to 9 parameters as exemplified in the following
If any of the angles or not specified they are implicitly set to 0
If no euler type is specified then the rotation matrix is the identity
1 t = Transform({"scale":2.0,"mirror":True,"tx":3.4,"ty":3,"tz":2}) # Rotation matrix is the identity
Similarly if any of the translation parameters are not specified they are implicitly set to 0
If scale is not specified it is by default 1.0, similarly if mirror is not specified it is be default False
1 t = Transform({"tx":3.4,"ty":3,"tz":3}) # scale is 1.0, mirror is False
A more in depth look at set_params
Constructing a Transform with some dictionary is the same as calling set_params on a Transform that is the identity.
The main difference between calling set_params explicitly on a Transform as opposed to constructing a Tranform with a dictionary lies in the fact that the construction method first sets the Transform object to the identity before calling set_params. So if calling the set_params function on a Transform that has already been initialized and had many things done than you should be aware of the following...
If unspecified, old parameters are retained