I have a warping grid, that has to be applied to an image. When I apply the grid, I get the results I expect.
Now, I want to apply the same grid to the same image, but the image is modified in the following way: it is rotated 270 degrees counterclockwise.
The grid is stored in memory as an array of points. It is [-1, -1] - [1, 1] normalized. I am trying to rotate the whole thing around the origin, that is [0, 0] id est the center of the image. Also, I am trying to rotate in discrete steps of 90 degrees.
P1 P2 P3 P4 P5 P6 P7 P8 P9
These are destination coordinates of the points in the image. For example, the lower right corner of the input image has coordinates of [1,1]. In the output image, this point is moved to [P9.x, P9.y] (a.k.a. forward mapping).
I transpose the matrix:
P1 P4 P7 P2 P5 P8 P3 P6 P9
Then I apply to every point the transformation
x = y' y = -x',
where ' denotes old coordinate and lack of prime denotes new coordinate. I apply the derived grid to the rotate
However, I do not get the expected warp. This task seemed incredibly simple to me, but I find myself struggling with the strange behaviour for a third day. Could someone point out my mistake or a procedure to get things right?