Changes between Initial Version and Version 1 of DevWikiRealParameters


Ignore:
Timestamp:
09/17/11 12:49:47 (13 years ago)
Author:
bnordgren
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DevWikiRealParameters

    v1 v1  
     1= How to calculate "real" parameters from affine transformation =
     2
     3== Introduction ==
     4
     5This page discusses how to compute conceptually meaningful parameters (i.e., rotation, scale in the x and y direction) when all you have is an affine transformation. The reverse process, calculating the affine parameters from the conceptually meaningful data, is articulated on [wiki:DevWikiAffineParameters another wiki page].
     6
     7As described on the page which discusses calculation of affine transform parameters, the value of each affine coefficient is affected by which operations the transformation performs, as well as the order in which the transform performs the operations. In essense, this means that we have to make an assumption about which operations are performed by the transform and hope that we made the right guess.
     8
     9== The forward calculation ==
     10
     11On the wiki page describing [wiki:DevWikiAffineParameters the reverse operation], a transform is developed which supports:
     12
     13 1. scaling
     14 1. clockwise rotation around the origin
     15 1. shearing parallel to the x axis
     16 1. shearing parallel to the y axis
     17
     18For the sake of consistency, we will use this same model and attempt to calculate the conceptually meaningful parameters from the transform coefficients. The above model produced the following equations:
     19
     20 * a,,11,, = o,,11,, = s,,x,, ( (1 + k,,x,, k,,y,,) cosθ + k,,y,, sinθ )
     21 * a,,12,, = o,,12,, = s,,x,, ( k,,x,, cosθ + sinθ )
     22 * a,,13,, = t,,x,,
     23 * a,,21,, = o,,21,, = s,,y,, ( -(1 + k,,x,, k,,y,,) sinθ + k,,y,, cosθ )
     24 * a,,22,, = o,,22,, = s,,y,, ( - k,,x,, sinθ + cosθ )
     25 * a,,23,, = t,,y,,
     26
     27where:
     28 * s,,x,, : scale factor in x direction
     29 * s,,y,, : scale factor in y direction
     30 * t,,x,, : offset in x direction
     31 * t,,y,, : offset in y direction
     32 * θ : angle of rotation clockwise around origin
     33 * k,,x,, : shearing parallel to x axis
     34 * k,,y,, : shearing parallel to y axis
     35
     36== Solving for the meaningful parameters ==
     37
     38The objective of this page is to find a way to determine values for s,,x,,, s,,y,,, t,,x,,, t,,y,,, θ, k,,x,,, and k,,y,, if all we know is a,,11,,,a,,12,,, ... a,,23,,. Clearly, t,,x,, and t,,y,, are trivial cases, because we can just use the values for a,,13,, and a,,23,, respectively. This leaves us with these four equations:
     39
     40 * a,,11,, = o,,11,, = s,,x,, ( (1 + k,,x,, k,,y,,) cosθ + k,,y,, sinθ )
     41 * a,,12,, = o,,12,, = s,,x,, ( k,,x,, cosθ + sinθ )
     42 * a,,21,, = o,,21,, = s,,y,, ( -(1 + k,,x,, k,,y,,) sinθ + k,,y,, cosθ )
     43 * a,,22,, = o,,22,, = s,,y,, ( - k,,x,, sinθ + cosθ )
     44
     45Unfortunately, these four equations contain five unknowns: s,,x,,, s,,y,,, θ, k,,x,,, and k,,y,,. This represents an ill-posed problem and forces us to simplify. Let's assume that there is no shearing. We are just going to declare upfront that k,,x,,=0 and k,,y,,=0. Remember that we did that because if we're wrong it will screw everything up. This makes the above into:
     46
     47 * a,,11,, = o,,11,, = s,,x,, cosθ
     48 * a,,12,, = o,,12,, = s,,x,, sinθ
     49 * a,,21,, = o,,21,, = - s,,y,, sinθ
     50 * a,,22,, = o,,22,, = s,,y,, cosθ
     51
     52Now we're on a roll. We can knock out s,,x,, and s,,y,, very easily:
     53
     54 * a,,11,,^2^ + a,,12,,^2^
     55  * = s,,x,,^2^ cos^2^θ + s,,x,,^2^ sin^2^θ
     56  * = s,,x,,^2^ (cos^2^θ + sin^2^θ)
     57  * = s,,x,,^2^ (1)
     58 * a,,21,,^2^ + a,,22,,^2^
     59  * = (- s,,y,,)^2^ sin^2^θ + s,,y,,^2^ cos^2^θ
     60  * = s,,y,,^2^ (sin^2^θ + cos^2^θ)
     61  * = s,,y,,^2^ (1)
     62
     63Rewriting as a "final result", this gives:
     64
     65 * s,,x,,^2^ = a,,11,,^2^ + a,,12,,^2^
     66 * s,,y,,^2^ = a,,21,,^2^ + a,,22,,^2^
     67
     68Checking this against the wikipedia page on the [http://en.wikipedia.org/wiki/World_file world file], which lists:
     69 * "pixel width" = s,,x,, = sqrt(A^2^ + D^2^) = sqrt(a,,11,,^2^ + a,,21,,^2^)
     70 * "pixel height" = s,,y,, = sqrt(B^2^ + E^2^) = sqrt(a,,12,,^2^ + a,,22,,^2^)
     71
     72Clearly, this does not match the answer on our page. The three possibilities are: we made a mistake; they made a mistake; or no one made a mistake, but we're using different models... The world file page does not declare it's assumptions about what operations are performed, or which order they are performed in. The world file page, however, also defines it's parameter A (for us: a,,11,,) as "pixel size in x direction".
     73
     74
     75