Rotation introduces black bars
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 979
- Forks
- 181
- Avg merge
- 5m
- Merged PRs (30d)
- 4
Description
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
fn test_rotate_half_pi_zero_square_about_center() {
let image = gray_image!(
00, 00, 00, 00;
00, 00, 00, 00;
00, 00, 00, 00;
00, 00, 00, 00);
let expected = gray_image!(
00, 00, 00, 00;
00, 00, 00, 00;
00, 00, 00, 00;
00, 00, 00, 00);
let rotated = rotate_about_center(
&image,
std::f32::consts::PI / 2f32,
Interpolation::Nearest,
Luma([99u8]),
);
assert_pixels_eq!(rotated, expected);
}
which fails because a bar of 99s has been introduced.
thread 'geometric_transformations::tests::test_rotate_half_pi_zero_square_about_center' panicked at 'pixels do not match.
Actual:
0 1 2
+-------------
|
0| 99 0 0
|
1| 99 0 0
|
2| 99 0 0
|
3| 99 0 0
|
Expected:
0 1 2
+----------
|
0| 0 0 0
|
1| 0 0 0
|
2| 0 0 0
|
3| 0 0 0
|
', src/geometric_transformations.rs:895:9
Rotating by pi introduces bars in the top and side.
Actual:
0 1 2 3
+-----------------
|
0| 99 99 99 99
|
1| 99 0 0 0
|
2| 99 0 0 0
|
3| 99 0 0 0
|
Expected:
0 1 2 3
+-------------
|
0| 0 0 0 0
|
1| 0 0 0 0
|
2| 0 0 0 0
|
3| 0 0 0 0
|
', src/geometric_transformations.rs:895:9
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.
---- geometric_transformations::tests::test_rotate_half_pi_square_about_center stdout ----
thread 'geometric_transformations::tests::test_rotate_half_pi_square_about_center' panicked at 'pixels do not match.
Actual:
0 1 2 3
+-----------------
|
0| 99 31 21 10
|
1| 99 32 22 11
|
2| 99 33 23 12
|
3| 99 34 25 14
|
Expected:
0 1 2 3
+-----------------
|
0| 31 21 10 0
|
1| 32 22 11 1
|
2| 33 23 12 2
|
3| 34 25 14 3
|
', src/geometric_transformations.rs:899:9
Some of these additional tests are there in this branch
https://github.com/chocolatier/imageproc/commits/fix_rotate
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/geometric_transformations.rs, especially rotate_about_center and the tests around line 895. Run the geometric transformation tests, including the square and zero-square cases shown in the issue, and compare the additional tests in the referenced fix_rotate branch. Done means rotations by pi/2, pi, and 3pi/2 about the center have no spurious bars or one-pixel offset.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100