wiki:DevWikiRealParameters

Version 2 (modified by bnordgren, 13 years ago) ( diff )

--

How to calculate "real" parameters from affine transformation

Introduction

This 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 another wiki page.

As 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.

The forward calculation

On the wiki page describing the reverse operation, a transform is developed which supports:

  1. scaling
  2. clockwise rotation around the origin
  3. shearing parallel to the x axis
  4. shearing parallel to the y axis

For 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:

  • a11 = o11 = sx ( (1 + kx ky) cosθ + ky sinθ )
  • a12 = o12 = sx ( kx cosθ + sinθ )
  • a13 = tx
  • a21 = o21 = sy ( -(1 + kx ky) sinθ + ky cosθ )
  • a22 = o22 = sy ( - kx sinθ + cosθ )
  • a23 = ty

where:

  • sx : scale factor in x direction
  • sy : scale factor in y direction
  • tx : offset in x direction
  • ty : offset in y direction
  • θ : angle of rotation clockwise around origin
  • kx : shearing parallel to x axis
  • ky : shearing parallel to y axis

Solving for the meaningful parameters

The objective of this page is to find a way to determine values for sx, sy, tx, ty, θ, kx, and ky if all we know is a11,a12, ... a23. Clearly, tx and ty are trivial cases, because we can just use the values for a13 and a23 respectively. This leaves us with these four equations:

  • a11 = o11 = sx ( (1 + kx ky) cosθ + ky sinθ )
  • a12 = o12 = sx ( kx cosθ + sinθ )
  • a21 = o21 = sy ( -(1 + kx ky) sinθ + ky cosθ )
  • a22 = o22 = sy ( - kx sinθ + cosθ )

Unfortunately, these four equations contain five unknowns: sx, sy, θ, kx, and ky. 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 kx=0 and ky=0. Remember that we did that because if we're wrong it will screw everything up. This makes the above into:

  • a11 = o11 = sx cosθ
  • a12 = o12 = sx sinθ
  • a21 = o21 = - sy sinθ
  • a22 = o22 = sy cosθ

Now we're on a roll. We can knock out sx and sy very easily:

  • a112 + a122
    • = sx2 cos2θ + sx2 sin2θ
    • = sx2 (cos2θ + sin2θ)
    • = sx2 (1)
  • a212 + a222
    • = (- sy)2 sin2θ + sy2 cos2θ
    • = sy2 (sin2θ + cos2θ)
    • = sy2 (1)

Rewriting as a "final result", this gives:

  • sx2 = a112 + a122
  • sy2 = a212 + a222

Checking against wikipedia

Checking this against the wikipedia page on the world file, which lists:

  • "pixel width" = sx = sqrt(A2 + D2) = sqrt(a112 + a212)
  • "pixel height" = sy = sqrt(B2 + E2) = sqrt(a122 + a222)

Clearly, 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: a11) as "pixel size in x direction".

NOTE: If the order of the model operations changes, in particular if scaling and rotation are swapped, then these pages match wikipedia. However, the math on wikipedia is unsourced. Since it has become clear that order is vital, and it is by no means guaranteed that all software performs uses the same model, it is probably vital to go out and determine which software performs the calculations which way before we do anything else.

Attachments (13)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.