Affine Transform - Geometry Correction in 2D Linear Space

It is pretty common that when people assemble a X-Y motion stage or a X-Y laser scanner, the resulting mechanics does not conform to a ideal Cartesian Coordinate. Often the error can include scales in X-Y does not match, or X-Y are not perpendicular, or neither X nor Y are matching the coordinate perfectly. Often the solution is quite straightforward, but often not simple, to download OpenCV and use computer to postprocess the image to correct for all geometric aberration. 

There are also cases, post-processing is not acceptable such as laser engraving or lithography patterning. In the cases when post-processing takes too much computational power or simply unacceptable as in manufacturing process, so sort of pre-correction must be applied. So, here we introduce a complete set of mathematics that correction all distortion in 2D linear space. Note that we are talking about 2D and linear space. 

The proper mathematical term of this is call Affine transform, also know as affine symmetry group. 

There are five basic operation in affine transform. 

  1. Translational shift
  2. Rotation
  3. Scaling
  4. Shearing
  5. Reflection

If you ask DeepSeek, the most popular AI chatbot at the time of this writing, to summarize Affine transform and geometry correction you will get something like this, and they are summarized pretty well. 

==== placeholder ====

So, here we are presenting the very special functionality built into the Chicago Laser Scanning Microscope (CLSM) software. 

The CLSM software take a six parameters input to archive full affine transform coverage for correcting all distortion in 2D linear space. The size parameters include:

  1. Scaling along X
  2. Scaling along Y
  3. Shearing along Y
  4. Rotation with respect to X
  5. Shift along X
  6. Shift along Y

For all real world implementation, there are always a few things that is not quite ideal. For CLSM:

  1. Scaling along X must be positive
  2. Shearing along Y is +/-90 deg
  3. Rotation with respect to X is +/-180 deg

There a many rational behind these artificially added constraints. For #1, the reason is to have a meaningful rotation number. What people typically expect when looking at a rotation number, it typically means the angle between the two X-axis in two coordinate system. However, if we allow scaling along X to be negative, we need to add 180 deg to the rotation. This unnecessary change of angle is very confusing and inconvenient. So for that, we artificially add a constraint to force scaling along X to be positive. 

So, now what if the end-user must use a negative scaling along X value? It is simple, in Affine transform, a reflection along X axis can be split into two actions as reflection along Y axis and a 180 deg rotation. So, instead of set scaling along X as negative, we instead set scaling along Y negative and add 180 deg to the rotation option. 

Rotation is a periodic function in polar coordinate. a 0 deg rotation is equivalent to a 360 deg rotation and also equivalent to 720 deg. So, basically we can end up with infinite amount of rotation to archive the same effect. This does not work well if we trying to compare two sets of parameters to figure out if they are identical, as what give the right to let computer tell me 0 deg is the same as 720 deg? So, artificially, we are taking the +/-180 deg as the preferred range of rotation angle. The CLSM program still takes in a number if they are outside of +/-180 deg, However, if a auto-calibration routine return a parameter, it will be within +/-18 deg. This is consistent with a common trigonometry function atan2(). 

Shearing is a different story. Shearing is less of a commonly used term. Often it is used in terms of skew. Skew is a just a number that introduce X shift based on Y position (or vs versa). However, a pure number is not quite intuitive for end-user. Thus, instead of using skew, we introduced shearing in deg for our geometry correction. To convert shearing to skew, a tangent function must be called. As you expected the +/-90 deg range is a property of the tangent function.