diff --git a/src/geometric_transformations.rs b/src/geometric_transformations.rs index 82f6221a..161fa88c 100644 --- a/src/geometric_transformations.rs +++ b/src/geometric_transformations.rs @@ -1013,32 +1013,6 @@ mod tests { assert_pixels_eq!(rotated, expected); } - #[test] - fn test_rotate_about_center_no_crop() { - let pixel_val = 255; - let square_size = 512; - - let image_area = square_size * square_size; - - let image = GrayImage::from_vec( - square_size, - square_size, - vec![pixel_val; image_area as usize], - ) - .unwrap(); - - let expected_proportion = image.iter().map(|&x| x as u32).sum::() as f32 - / (pixel_val as u32 * image_area) as f32; - - let rotated_image = - rotate_about_center_no_crop(&image, PI * 0.25, Interpolation::Nearest, Luma([0])); - - let rotated_proportion = rotated_image.iter().map(|&x| x as u32).sum::() as f32 - / (pixel_val as u32 * image_area) as f32; - - assert_approx_eq!(rotated_proportion, expected_proportion, 0.01); - } - #[test] fn test_translate_positive_x_positive_y() { let image = gray_image!( diff --git a/tests/data/truth/elephant_rotate_no_crop_bicubic.png b/tests/data/truth/elephant_rotate_no_crop_bicubic.png new file mode 100644 index 00000000..c7c89919 Binary files /dev/null and b/tests/data/truth/elephant_rotate_no_crop_bicubic.png differ diff --git a/tests/data/truth/elephant_rotate_no_crop_bicubic_rgba.png b/tests/data/truth/elephant_rotate_no_crop_bicubic_rgba.png new file mode 100644 index 00000000..3a589755 Binary files /dev/null and b/tests/data/truth/elephant_rotate_no_crop_bicubic_rgba.png differ diff --git a/tests/data/truth/elephant_rotate_no_crop_bilinear.png b/tests/data/truth/elephant_rotate_no_crop_bilinear.png new file mode 100644 index 00000000..d601a11f Binary files /dev/null and b/tests/data/truth/elephant_rotate_no_crop_bilinear.png differ diff --git a/tests/data/truth/elephant_rotate_no_crop_bilinear_rgba.png b/tests/data/truth/elephant_rotate_no_crop_bilinear_rgba.png new file mode 100644 index 00000000..cac81b3e Binary files /dev/null and b/tests/data/truth/elephant_rotate_no_crop_bilinear_rgba.png differ diff --git a/tests/data/truth/elephant_rotate_no_crop_nearest.png b/tests/data/truth/elephant_rotate_no_crop_nearest.png new file mode 100644 index 00000000..b7e8b83e Binary files /dev/null and b/tests/data/truth/elephant_rotate_no_crop_nearest.png differ diff --git a/tests/data/truth/elephant_rotate_no_crop_nearest_rgba.png b/tests/data/truth/elephant_rotate_no_crop_nearest_rgba.png new file mode 100644 index 00000000..817f6c9b Binary files /dev/null and b/tests/data/truth/elephant_rotate_no_crop_nearest_rgba.png differ diff --git a/tests/regression.rs b/tests/regression.rs index a8e478df..952aa40f 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -25,6 +25,7 @@ use imageproc::contrast::ThresholdType; use imageproc::definitions::Image; use imageproc::filter::bilateral::GaussianEuclideanColorDistance; use imageproc::filter::bilateral_filter; +use imageproc::geometric_transformations::rotate_about_center_no_crop; use imageproc::kernel::{self}; use imageproc::{ definitions::{Clamp, HasBlack, HasWhite}, @@ -142,6 +143,30 @@ fn test_rotate_nearest_rgb() { ); } +/* + let input = Image::>::from_dynamic(&load_image_or_panic( + Path::new(INPUT_DIR).join("elephant.png"), + )); + println!("{:?}", rotate_bicubic_about_center_no_crop(&input).save(Path::new(TRUTH_DIR).join("elephant_rotate_no_crop_bicubic.png"))); +*/ + +#[test] +fn test_rotate_no_crop_nearest_rgb() { + fn rotate_nearest_about_center_no_crop(image: &RgbImage) -> RgbImage { + rotate_about_center_no_crop( + image, + std::f32::consts::PI / 4f32, + Interpolation::Nearest, + Rgb::black(), + ) + } + compare_to_truth( + "elephant.png", + "elephant_rotate_no_crop_nearest.png", + rotate_nearest_about_center_no_crop, + ); +} + #[test] fn test_rotate_nearest_rgba() { fn rotate_nearest_about_center(image: &RgbaImage) -> RgbaImage { @@ -159,6 +184,23 @@ fn test_rotate_nearest_rgba() { ); } +#[test] +fn test_rotate_no_crop_nearest_rgba() { + fn rotate_nearest_about_center_no_crop(image: &RgbaImage) -> RgbaImage { + rotate_about_center_no_crop( + image, + std::f32::consts::PI / 4f32, + Interpolation::Nearest, + Rgba::black(), + ) + } + compare_to_truth( + "elephant_rgba.png", + "elephant_rotate_no_crop_nearest_rgba.png", + rotate_nearest_about_center_no_crop, + ); +} + #[test] fn test_equalize_histogram_grayscale() { use imageproc::contrast::equalize_histogram; @@ -183,6 +225,24 @@ fn test_rotate_bilinear_rgb() { ); } +#[test] +fn test_rotate_bilinear_no_crop_rgb() { + fn rotate_bilinear_about_center_no_crop(image: &RgbImage) -> RgbImage { + rotate_about_center_no_crop( + image, + std::f32::consts::PI / 4f32, + Interpolation::Bilinear, + Rgb::black(), + ) + } + compare_to_truth_with_tolerance( + "elephant.png", + "elephant_rotate_no_crop_bilinear.png", + rotate_bilinear_about_center_no_crop, + 2, + ); +} + #[test] fn test_rotate_bilinear_rgba() { fn rotate_bilinear_about_center(image: &RgbaImage) -> RgbaImage { @@ -201,6 +261,24 @@ fn test_rotate_bilinear_rgba() { ); } +#[test] +fn test_rotate_no_crop_bilinear_rgba() { + fn rotate_bilinear_about_center_no_crop(image: &RgbaImage) -> RgbaImage { + rotate_about_center_no_crop( + image, + std::f32::consts::PI / 4f32, + Interpolation::Bilinear, + Rgba::black(), + ) + } + compare_to_truth_with_tolerance( + "elephant_rgba.png", + "elephant_rotate_no_crop_bilinear_rgba.png", + rotate_bilinear_about_center_no_crop, + 2, + ); +} + #[test] fn test_rotate_bicubic_rgb() { fn rotate_bicubic_about_center(image: &RgbImage) -> RgbImage { @@ -219,6 +297,24 @@ fn test_rotate_bicubic_rgb() { ); } +#[test] +fn test_rotate_no_crop_bicubic_rgb() { + fn rotate_bicubic_about_center_no_crop(image: &RgbImage) -> RgbImage { + rotate_about_center_no_crop( + image, + std::f32::consts::PI / 4f32, + Interpolation::Bicubic, + Rgb::black(), + ) + } + compare_to_truth_with_tolerance( + "elephant.png", + "elephant_rotate_no_crop_bicubic.png", + rotate_bicubic_about_center_no_crop, + 2, + ); +} + #[test] fn test_rotate_bicubic_rgba() { fn rotate_bicubic_about_center(image: &RgbaImage) -> RgbaImage { @@ -237,6 +333,24 @@ fn test_rotate_bicubic_rgba() { ); } +#[test] +fn test_rotate_no_crop_bicubic_rgba() { + fn rotate_bicubic_about_center_no_crop(image: &RgbaImage) -> RgbaImage { + rotate_about_center( + image, + std::f32::consts::PI / 4f32, + Interpolation::Bicubic, + Rgba::black(), + ) + } + compare_to_truth_with_tolerance( + "elephant_rgba.png", + "elephant_rotate_no_crop_bicubic_rgba.png", + rotate_bicubic_about_center_no_crop, + 2, + ); +} + #[test] fn test_affine_nearest_rgb() { fn affine_nearest(image: &RgbImage) -> RgbImage {