# Changes between Version 5 and Version 6 of DevWikiAffineParameters

Show
Ignore:
Timestamp:
09/13/11 10:58:24 (21 months ago)
Comment:

--

Unmodified
Added
Removed
Modified
• ## DevWikiAffineParameters

v5 v6
6161
6262 1. scaling
63  1. clockwise rotation
63 1. clockwise rotation around the origin
6464 1. shearing parallel to the x axis
6565 1. shearing parallel to the y axis

8888[[Image(aggregate_usage.png)]]
8989
90 * x' = o,,11,, x + o,,12,, y
91 * y' = o,,21,, x + o,,22,, y
9092
93== Constructing the affine transformation ==
9194
92 Sx : scale in the x direction
93 Sy : scale in the y direction
94 Tx : translation in the x direction
95 Ty : translation in the y direction
96 Kx : shearing parallel to x axis
97 Ky : shearing parallel to y axis
98 theta : angle of rotation CLOCKWISE around the origin (not around the
99 x axis, not around the y axis: around the origin; or if you like,
100 around the invisible Z axis coming out of the screen and poking you in
101 the eye.)
95The 2x2 matrix '''O''' is the upper-left hand corner of the affine transformation, which is the 3x3 matrix, '''A'''. The right hand column contains the offsets, or translation, of the raster in the x and y directions. The bottom row is always filled with the numbers 0, 0, 1. The result of this is that there are six parameters to an affine transformation which can actually change, as shown:
10296
103 The next step is to define an order. I chose: "Scale followed by
104 rotation followed by shearing (skew)".
97[[Image(affinematrix.png)]]
10598
106 Multiplying these matrices together, as described here
107 (http://en.wikipedia.org/wiki/Transformation_matrix#Composing_and_inverting_transformations)
108 gives a 2x2 matrix, which is not an affine transform yet. Let's label
109 the coefficients of this matrix as follows
99 * a,,11,, = o,,11,, = s,,x,, ( (1 + k,,x,, k,,y,,) cosθ + k,,y,, sinθ )
100 * a,,12,, = o,,12,, = s,,x,, ( k,,x,, cosθ + sinθ )
101 * a,,13,, = t,,x,,
102 * a,,21,, = o,,21,, = s,,y,, ( -(1 + k,,x,, k,,y,,) sinθ + k,,y,, cosθ )
103 * a,,22,, = o,,22,, = s,,y,, ( - k,,x,, sinθ + cosθ )
104 * a,,23,, = t,,y,,
110105
111 | O11  O12 |
112 | O21  O22 |
106where:
107 * s,,x,, : scale factor in x direction
108 * s,,y,, : scale factor in y direction
109 * t,,x,, : offset in x direction
110 * t,,y,, : offset in y direction
111 * θ : angle of rotation clockwise around origin
112 * k,,x,, : shearing parallel to x axis
113 * k,,y,, : shearing parallel to y axis
113114
114 (I apologize for the ascii graphics throughout. Gmail is not using a
115 monospaced font even in "plain text" mode.)
115It is these six parameters (a,,11,,...a,,23,,)which are typically stored within a geospatial image file format to record the conversion from pixel index to geolocation. The actual conversion is described as follows:
116116
117 So what I get for these coefficients (after multiplying in the order
118 specified) is:
117[[Image(affineusage.png)]]
119118
120 O11 = Sx * (cos(theta) + Ky sin(theta))
121 O12 = Sx * (Kx cos(theta) + sin(theta))
122 O21 = Sy * (-sin(theta) + Ky cos(theta))
123 O22 = Sy * (-Kx * sin(theta) + cos(theta))
119 * E = a,,11,, i + a,,12,, j + a,,13,,
120 * N = a,,21,, i + a,,22,, j + a,,23,,
124121
125 And the final bit is to add translation by making this into an affine transform:
122where E is easting, N is northing, i is pixel column and j is pixel row. The last row of the matrix equation is always ignored, as it boils down to 1=1. It is there to make a square matrix used to calculate the inverse operation.
126123
127 | O11 O12 O13 |
128 | O21 O22 O23 |
129 |   0      0     1    |
124== Link to postgis raster ==
130125
131 where:
126The six parameters of the affine transform are given the following names in postgis raster:
132127
133 O13 = Tx
134 O23 = Ty
128 * ScaleX = a,,11,,
129 * SkewX =  a,,12,,
130 * OffsetX = a,,13,, = t,,x,,
131 * SkewY =  a,,21,,
132 * ScaleY = a,,22,,
133 * OffsetY = a,,23,, = t,,y,,
135134
136 To be pedantic, this is used as follows:
135With the exception of OffsetX and OffsetY, the names are somewhat arbitrary for the general case.
137136
138 | E |         | O11 O12 O13 |  | i |
139 | N |   =   | O21 O22 O23 |  | j |
140 | 1 |         |    0     0     1   |   | 1 |
137== Summary ==
141138
142 where:
143 E  = easting
144 N = northing
145 i   = pixel column
146 j   = pixel row
147
148
149 The coefficients map onto our jumbled named coefficients as follows :
150
151 ScaleX = O11
152 SkewX = O12
153 OffsetX = O13
154 SkewY = O21
155 ScaleY = O22
156 OffsetY = O23
157
158 The important thing to note is that the things we're rather loosely
159 calling Scale[XY] and Skew[XY] represent all of Scale, Rotation and
160 Shearing. This dictates that you cannot set these coefficients without
161 knowing all three.
139Throughout this page, the following symbols have been