|
4 | 4 |
|
5 | 5 | import numpy as np |
6 | 6 | import pytest |
7 | | -from arduino.app_utils.image.adjustments import letterbox, resize, adjust, split_channels, greyscale |
| 7 | +from arduino.app_utils.image.adjustments import letterbox, resize, adjust, split_channels, greyscale, flip_h, flip_v |
8 | 8 |
|
9 | 9 |
|
10 | 10 | # FIXTURES |
@@ -440,3 +440,55 @@ def test_letterbox_color_tuple_error(frame_bgr_uint8): |
440 | 440 | # BGRA (4-ch) frame with 3-ch padding |
441 | 441 | frame_bgra = create_bgra_frame(np.uint8) |
442 | 442 | letterbox(frame_bgra, (200, 200), color=(0, 0, 0)) |
| 443 | + |
| 444 | + |
| 445 | +def test_flip_h_bgr(frame_bgr_uint8): |
| 446 | + """Test horizontal flip for BGR image.""" |
| 447 | + flipped = flip_h(frame_bgr_uint8) |
| 448 | + # Flipping twice should return the original |
| 449 | + assert np.array_equal(flip_h(flipped), frame_bgr_uint8) |
| 450 | + # Check that first column becomes last |
| 451 | + assert np.array_equal(flipped[:, 0, :], frame_bgr_uint8[:, -1, :]) |
| 452 | + assert np.array_equal(flipped[:, -1, :], frame_bgr_uint8[:, 0, :]) |
| 453 | + |
| 454 | + |
| 455 | +def test_flip_v_bgr(frame_bgr_uint8): |
| 456 | + """Test vertical flip for BGR image.""" |
| 457 | + flipped = flip_v(frame_bgr_uint8) |
| 458 | + # Flipping twice should return the original |
| 459 | + assert np.array_equal(flip_v(flipped), frame_bgr_uint8) |
| 460 | + # Check that first row becomes last |
| 461 | + assert np.array_equal(flipped[0, :, :], frame_bgr_uint8[-1, :, :]) |
| 462 | + assert np.array_equal(flipped[-1, :, :], frame_bgr_uint8[0, :, :]) |
| 463 | + |
| 464 | + |
| 465 | +def test_flip_h_greyscale(frame_grey_uint8): |
| 466 | + """Test horizontal flip for greyscale image.""" |
| 467 | + flipped = flip_h(frame_grey_uint8) |
| 468 | + assert np.array_equal(flip_h(flipped), frame_grey_uint8) |
| 469 | + assert np.array_equal(flipped[:, 0], frame_grey_uint8[:, -1]) |
| 470 | + assert np.array_equal(flipped[:, -1], frame_grey_uint8[:, 0]) |
| 471 | + |
| 472 | + |
| 473 | +def test_flip_v_greyscale(frame_grey_uint8): |
| 474 | + """Test vertical flip for greyscale image.""" |
| 475 | + flipped = flip_v(frame_grey_uint8) |
| 476 | + assert np.array_equal(flip_v(flipped), frame_grey_uint8) |
| 477 | + assert np.array_equal(flipped[0, :], frame_grey_uint8[-1, :]) |
| 478 | + assert np.array_equal(flipped[-1, :], frame_grey_uint8[0, :]) |
| 479 | + |
| 480 | + |
| 481 | +def test_flip_h_bgra(frame_bgra_uint8): |
| 482 | + """Test horizontal flip for BGRA image.""" |
| 483 | + flipped = flip_h(frame_bgra_uint8) |
| 484 | + assert np.array_equal(flip_h(flipped), frame_bgra_uint8) |
| 485 | + assert np.array_equal(flipped[:, 0, :], frame_bgra_uint8[:, -1, :]) |
| 486 | + assert np.array_equal(flipped[:, -1, :], frame_bgra_uint8[:, 0, :]) |
| 487 | + |
| 488 | + |
| 489 | +def test_flip_v_bgra(frame_bgra_uint8): |
| 490 | + """Test vertical flip for BGRA image.""" |
| 491 | + flipped = flip_v(frame_bgra_uint8) |
| 492 | + assert np.array_equal(flip_v(flipped), frame_bgra_uint8) |
| 493 | + assert np.array_equal(flipped[0, :, :], frame_bgra_uint8[-1, :, :]) |
| 494 | + assert np.array_equal(flipped[-1, :, :], frame_bgra_uint8[0, :, :]) |
0 commit comments