Skip to content

Affine transformation in image processing

An answer to this question on Stack Overflow.

Question

Reading the below:

enter image description here

Example input image:

enter image description here

Affine matrix:

Matrix

Output:

Output

Is this output correct? If I try to apply the formula above I get a different answer. For example pixel: 20 at (2,0) x’ = 22 + 00 + 0 = 4 y’ = 02 + 1y + 0 = 0 So the new coordinates should be (4,0) instead of (1,0) What am I doing wrong?

Answer

If you're doing this in a loop it's possible that you are overwriting cells before you have a chance to adjust their values.

You'll want to ensure that you allocate a new matrix and then loop over the old matrix in order to set the new matrix's values.