diff --git a/tests/test_regression/images/lenna.png b/tests/test_regression/images/lenna.png new file mode 100644 index 0000000..59ef68a Binary files /dev/null and b/tests/test_regression/images/lenna.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_1.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_1.png new file mode 100644 index 0000000..ca0b289 Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_1.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_10.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_10.png new file mode 100644 index 0000000..1d9ca8d Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_10.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_2.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_2.png new file mode 100644 index 0000000..e80f2de Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_2.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_3.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_3.png new file mode 100644 index 0000000..d61056c Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_3.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_4.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_4.png new file mode 100644 index 0000000..f9602d6 Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_4.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_5.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_5.png new file mode 100644 index 0000000..0f389da Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_5.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_6.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_6.png new file mode 100644 index 0000000..08777b1 Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_6.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_7.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_7.png new file mode 100644 index 0000000..17c8b2c Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_7.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_8.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_8.png new file mode 100644 index 0000000..48bd8e3 Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_8.png differ diff --git a/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_9.png b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_9.png new file mode 100644 index 0000000..38b8976 Binary files /dev/null and b/tests/test_regression/images/sinusoidal_rotation/rotated_lenna_9.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_1.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_1.png new file mode 100644 index 0000000..40e12e5 Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_1.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_10.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_10.png new file mode 100644 index 0000000..917610f Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_10.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_2.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_2.png new file mode 100644 index 0000000..21768dd Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_2.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_3.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_3.png new file mode 100644 index 0000000..51669b8 Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_3.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_4.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_4.png new file mode 100644 index 0000000..a6b10ab Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_4.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_5.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_5.png new file mode 100644 index 0000000..4e54c60 Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_5.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_6.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_6.png new file mode 100644 index 0000000..53464b9 Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_6.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_7.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_7.png new file mode 100644 index 0000000..1b16c49 Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_7.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_8.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_8.png new file mode 100644 index 0000000..8c4d46c Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_8.png differ diff --git a/tests/test_regression/images/uniform_rotation/rotated_lenna_9.png b/tests/test_regression/images/uniform_rotation/rotated_lenna_9.png new file mode 100644 index 0000000..ef89043 Binary files /dev/null and b/tests/test_regression/images/uniform_rotation/rotated_lenna_9.png differ diff --git a/tests/test_regression/test_derotation_by_line.py b/tests/test_regression/test_derotation_by_line.py new file mode 100644 index 0000000..149da4d --- /dev/null +++ b/tests/test_regression/test_derotation_by_line.py @@ -0,0 +1,65 @@ +import numpy as np +import pytest +from PIL import Image + +from derotation.analysis.derotation_pipeline import DerotationPipeline + +lenna = Image.open("tests/test_regression/images/lenna.png").convert("L") + + +@pytest.fixture +def len_stack(): + return 10 + + +@pytest.fixture +def image_stack(len_stack): + image_stack = np.array([np.array(lenna) for _ in range(len_stack)]) + return image_stack + + +@pytest.fixture +def n_lines(image_stack): + return image_stack.shape[1] + + +@pytest.fixture +def n_total_lines(image_stack, n_lines): + return image_stack.shape[0] * n_lines + + +def get_angles(kind, n_lines, n_total_lines): + if kind == "uniform": + rotation = np.linspace(0, 360, n_total_lines - n_lines) + elif kind == "sinusoidal": + rotation = ( + np.sin(np.linspace(0, 2 * np.pi, n_total_lines - n_lines)) * 360 + ) + all_angles = np.zeros(n_total_lines) + all_angles[n_lines // 2 : -n_lines // 2] = rotation + + return all_angles + + +def test_rotation_by_line(image_stack, n_lines, n_total_lines, len_stack): + pipeline = DerotationPipeline.__new__(DerotationPipeline) + pipeline.image_stack = image_stack + + for kind in ["uniform", "sinusoidal"]: + pipeline.rot_deg_line = get_angles(kind, n_lines, n_total_lines) + pipeline.num_lines_per_frame = n_lines + + rotated_images = pipeline.rotate_frames_line_by_line() + + assert len(rotated_images) == len_stack + assert rotated_images[0].shape == (n_lines, n_lines) + + for i, image in enumerate(rotated_images): + target_image = Image.open( + "tests/test_regression/images/" + + f"{kind}_rotation/rotated_lenna_{i + 1}.png" + ) + target_image = np.array(target_image.convert("L")) + assert np.allclose( + image, target_image, atol=1 + ), f"Failed for {kind} rotation, image {i + 1}"