Changes between Version 7 and Version 8 of DevWikiAffineParameters


Ignore:
Timestamp:
Nov 27, 2011, 12:51:20 PM (12 years ago)
Author:
bnordgren
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • DevWikiAffineParameters

    v7 v8  
    33== Introduction ==
    44
    5 Geospatial rasters inherently have two coordinate systems associated with them: pixel indices and real world coordinates. Although some rasters have a very complex relationship between these two coordinate systems, many have a set of simple linear relationships between the two coordinate systems. These simple linear relationships are ''modular'' and may be combined in many ways. Regardless of the order in which they are combined, an affine transform results. The transform is then used to convert coordinates between the two coordinate systems of the raster. This page describes a set of ubiquitous individual transformations and demonstrates how they may be combined to produce an affine transformation.
     5Geospatial rasters inherently have two coordinate systems associated with them: pixel indices (i,j) and real world coordinates (x,y). For the simple case covered on this page, where a linear transform is sufficient to relate the two coordinate systems, physically significant parameters may be used to define the linear relation. These physically significant parameters control the magnitude and orientation of the basis vectors '''i,,b,,''' and '''j,,b,,''' defined in the following figure:
     6
     7[[Image(construction-step5.png)]]
     8
     9
     10Although some rasters have a very complex relationship between these two coordinate systems, many have a set of simple linear relationships between the two coordinate systems. These simple linear relationships are ''modular'' and may be combined in many ways. Regardless of the order in which they are combined, an affine transform results. The transform is then used to convert coordinates between the two coordinate systems of the raster. This page describes a set of ubiquitous individual transformations and combines them to produce a specific affine transformation which adheres to the .
    611
    712The level of math required to follow along is advanced high school algebra or introductory college algebra. It should be accessible to anyone with a science, math, or engineering background. Lacking this, the nontechnical introduction to [http://en.wikipedia.org/wiki/Matrix_multiplication matrix multiplication] on wikipedia should provide sufficient background.
     
    914== Individual operations ==
    1015
    11 This page discusses operations in two dimensions only. Each operation is presented as a 2x2 matrix, and each operation performs only one function.  These operations were taken from [http://en.wikipedia.org/wiki/Transformation_matrix#Examples_in_2D_graphics wikipedia]. While the matrices presented here contain the bulk of the functionality of a finished affine transform, they are not ''complete'' affine transforms themselves. Each transformation will be presented in matrix and equation form: they are equivilent representations.
     16This page discusses operations in two dimensions only. Each operation is presented as a 2x2 matrix, and each operation performs only one function.  These operations were taken from [http://en.wikipedia.org/wiki/Transformation_matrix#Examples_in_2D_graphics wikipedia]. While the matrices presented here contain the bulk of the functionality of a finished affine transform, they are not ''complete'' affine transforms themselves. Each transformation will be presented in matrix and equation form: they are equivalent representations.
    1217
    1318=== Rotation ===
     
    5459 * y' = k,,y,,x + y
    5560
     61=== Reflection ===
     62
     63Reflection across the x axis (or "flipping" the y axis) is accomplished with the following transform:
     64
     65[[Image(reflect_x.png)]]
     66
     67 * x' = x
     68 * y' = -y
     69
     70
    5671== Combining individual operations ==
    5772
    58 Whenever more than one of the above operations is required, they may be combined using [http://en.wikipedia.org/wiki/Matrix_multiplication matrix multiplication]. As an example, all of the above matrices will be combined into one. The result of such a combination is still not an affine transform, however. It is just a 2x2 matrix has all the individual functions aggregated into it.
     73Whenever more than one of the above operations is required, they may be combined using [http://en.wikipedia.org/wiki/Matrix_multiplication matrix multiplication]. As an example, all of the above matrices will be combined into one. The result of such a combination is still not an affine transform, however. It is just a 2x2 matrix which has all the individual transformation functions aggregated into it.
    5974
    6075We will be calculating a new matrix, '''O''', which is the aggregate of the following individual operations:
    6176
    62  1. scaling
    63  1. clockwise rotation around the origin
    64  1. shearing parallel to the x axis
    65  1. shearing parallel to the y axis
     77 1. Reflection across the i axis
     78 1. Scaling along the i and j axes
     79 1. Shearing parallel to the i axis
     80 1. clockwise rotation around the origin (by θ,,i,,)
    6681
    6782We do this by multiplying the 2x2 matrices of the individual operations together, as follows:
     
    6984[[Image(aggregate_step1.png)]]
    7085
    71 The above matrix equation is shorthand for four equations: one equation each for o,,11,,, o,,12,,, o,,21,, and o,,22,,. We will perform the multiplications on the right hand side one at a time.
     86We will perform the matrix multiplications on the right hand side one at a time.
    7287
    7388[[Image(aggregate_step2.png)]]
     
    7792[[Image(aggregate_step4.png)]]
    7893
    79  * o,,11,, = s,,x,, ( (1 + k,,x,, k,,y,,) cosθ + k,,y,, sinθ )
    80  * o,,12,, = s,,x,, ( k,,x,, cosθ + sinθ )
    81  * o,,21,, = s,,y,, ( -(1 + k,,x,, k,,y,,) sinθ + k,,y,, cosθ )
    82  * o,,22,, = s,,y,, ( - k,,x,, sinθ + cosθ )
     94The above matrix equation is shorthand for four equations: one equation each for o,,11,,, o,,12,,, o,,21,, and o,,22,,.
    8395
    84 Notice that none of the coefficients in the '''O''' matrix may be said to represent pure scaling, rotation or shearing. Rather, they all have components of each of these operations factored in. If a particular transformation is not needed (say there is no shearing in either the x or y directions), then the relevant parameters may be set to zero (k,,x,, = k,,y,, = 0).
     96 * o,,11,, = s,,i,, cos(θ,,i,,)
     97 * o,,12,, = k,,i,, s,,j,, f cos(θ,,i,,) + s,,j,, f sin(θ,,i,,)
     98 * o,,21,, = -s,,i,, sin(θ,,i,,)
     99 * o,,22,, = -k,,i,, s,,j,, f sin(θ,,i,,) + s,,j,, f cos(θ,,i,,)
     100
     101Notice that none of the coefficients in the '''O''' matrix may be said to represent pure scaling, rotation or shearing. Rather, they all have components of each of these operations factored in. The final matrix equation has some terms which need to be calculated. This will be performed in the next section using the real input parameters. Once these terms have been calculated, they may be plugged into the above equations to arrive at the coefficients which must be stored in the geotransform matrix.
    85102
    86103Also notice that it is not necessary to compute this matrix every time one wants to convert between pixel indices and geographic location. The coefficients are computed once for the entire raster, and may be reused for every pixel calculation. You would use this aggregate matrix '''O''' exactly as you would use any of the individual matrices:
     
    88105[[Image(aggregate_usage.png)]]
    89106
    90  * x' = o,,11,, x + o,,12,, y
    91  * y' = o,,21,, x + o,,22,, y
     107 * x' = o,,11,, i + o,,12,, j
     108 * y' = o,,21,, i + o,,22,, j
    92109
    93110== Constructing the affine transformation ==