Open chocolatier opened 4 years ago
[I'm not 100% on how the code works, so I might be wrong, but...]
I think this is because the projection matrix takes the origin as the top left pixel (0,0). Since pixels encompass an area 1px*1px wide, directly applying the rotation is taking centre to be the top left pixel (0,0), i.e. (0.5,0.5).
Adding a half pixel offset while rotating fixes this issue, but breaks the regression tests.
Projection::translate(cx -0.5, cy - 0.5) * Projection::rotate(theta) * Projection::translate(-cx + 0.5, -cy + 0.5);
Adding a half-pixel offset while rotating fixes this issue, but breaks the regression tests.
I thought this was the problem, but it turned out not to be. If you fix it as you have suggested, some other rotations get broken.
I have attempted to solve this issue in myriad ways now, but could not find a solution.
Could you tell me which other rotations this breaks (other than the regression tests, which are too large for me to compute by hand :).
The issue in #391 is also present in the cropping rotate function.
Rotating a square by multiples of pi/2 about centre shouldn't have any pixels with a preimage outside the original square. But calling rotate_about_center introduces bars of 99s.
I've added the following test
which fails because a bar of 99s has been introduced.
Rotating by pi introduces bars in the top and side.
Similarly, rotating by 3pi/2 introduces a black bar at the top. Testing with non-zero squares shows that the result square is offset by one pixel.
Some of these additional tests are there in this branch https://github.com/chocolatier/imageproc/commits/fix_rotate