-
Notifications
You must be signed in to change notification settings - Fork 8
Expose YUV Comparison and Utilities #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b4c2cd5
4a93df3
5e473dc
da9d4f6
7ab75ef
708e57c
64b3b8a
7a877b2
38e659f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||
| Feature: Decompose trait test | ||||||
|
|
||||||
| Scenario Outline: Compare newly split yuv channels to expected values | ||||||
| Given the image '<full_image>' is loaded | ||||||
| When comparing yuv channels | ||||||
| Then check split success | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
then steps should be formulated in passive, but this is just a hint - I can fix this later :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will keep that in mind for future use- was the first time i'd worked with that test runner |
||||||
|
|
||||||
| Examples: | ||||||
| | full_image | | ||||||
| | tests/data/pad_gaprao.png | | ||||||
| | tests/data/pad_gaprao_lighter.png | | ||||||
| | tests/data/pad_gaprao_noise.png | | ||||||
| | tests/data/pad_gaprao_gray_inverted.png | | ||||||
| | tests/data/pad_gaprao_color_filters.png | | ||||||
| | tests/data/colored_primitives_swapped.png | | ||||||
| | tests/data/colored_primitives_hybrid_compare_rgb.png | | ||||||
| | tests/data/colored_primitives.png | | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Scenario Outline: Compare newly split yuv channels to expected values | ||||||
| Given the image '<full_image>' is loaded | ||||||
| When comparing rgb channels | ||||||
| Then check split success | ||||||
|
|
||||||
| Examples: | ||||||
| | full_image | | ||||||
| | tests/data/pad_gaprao.png | | ||||||
| | tests/data/pad_gaprao_lighter.png | | ||||||
| | tests/data/pad_gaprao_noise.png | | ||||||
| | tests/data/pad_gaprao_gray_inverted.png | | ||||||
| | tests/data/pad_gaprao_color_filters.png | | ||||||
| | tests/data/colored_primitives_swapped.png | | ||||||
| | tests/data/colored_primitives_hybrid_compare_rgb.png | | ||||||
| | tests/data/colored_primitives.png | | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| Feature: YUV image comparison using hybrid mode - MSSIM for for Y channel, RMS for U and V | ||
|
|
||
| Scenario: Comparing an image to the original with hybrid mode and checking the difference image | ||
| Given the images 'tests/data/colored_primitives.png' and 'tests/data/colored_primitives_swapped.png' are loaded | ||
| When comparing the images using the hybrid mode as yuv | ||
| Then the YUV similarity image matches 'tests/data/colored_primitives_hybrid_compare_rgb.png' | ||
|
|
||
|
|
||
| Scenario Outline: Comparing a modified image to the original using hybrid mode algorithm | ||
| Given the images 'tests/data/pad_gaprao.png' and '<compare_image>' are loaded | ||
| When comparing the images using the hybrid mode as yuv | ||
| Then the similarity score is <result> | ||
|
|
||
| Examples: | ||
| | compare_image | result | | ||
| | tests/data/pad_gaprao.png | 1.0 | | ||
| | tests/data/pad_gaprao_lighter.png | 0.9514066504143178 | | ||
| | tests/data/pad_gaprao_noise.png | 0.13009783371684705 | | ||
| | tests/data/pad_gaprao_gray_inverted.png | 3.2566565189821024e-5 | | ||
| | tests/data/pad_gaprao_color_filters.png | 0.9876923700357477 | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use cucumber::{given, then, when, World}; | ||
| use image::DynamicImage; | ||
| use image_compare::prelude::*; | ||
| extern crate image; | ||
|
|
||
| #[cfg(feature = "yuv_compare")] // Do not remove, ensures rgb_to_yuv stays public not pub(crate) or private | ||
| use image_compare::utils::rgb_to_yuv; | ||
| #[cfg(feature = "yuv_compare")] // Do not remove, ensures yuv_to_rgb stays public not pub(crate) or private | ||
| use image_compare::utils::yuv_to_rgb; | ||
|
|
||
| // `World` is your shared, likely mutable state. | ||
| #[derive(Debug, World, Default)] | ||
| pub struct SplitWorld { | ||
| image: Option<DynamicImage>, | ||
| channel_r: Option<GrayImage>, | ||
| channel_g: Option<GrayImage>, | ||
| channel_b: Option<GrayImage>, | ||
| channel_y: Option<GrayImage>, | ||
| channel_u: Option<GrayImage>, | ||
| channel_v: Option<GrayImage>, | ||
| success: Option<bool> | ||
| } | ||
|
|
||
| #[cfg(feature = "yuv_compare")] | ||
| #[given(expr = "the image {string} is loaded")] | ||
| fn load_images(world: &mut SplitWorld, image: String) { | ||
| let full_image = image::open(image.clone()).expect(format!("Could not find test-image {}", image).as_str()); | ||
| world.image = Some(full_image.clone()); | ||
| world.channel_y = Some(image::open(image.clone().replace(".png", "_y_channel.png")).expect("Could not load y_channel").to_luma8()); // Automatically loads images | ||
| world.channel_u = Some(image::open(image.clone().replace(".png", "_u_channel.png")).expect("Could not load u_channel").to_luma8()); | ||
| world.channel_v = Some(image::open(image.clone().replace(".png", "_v_channel.png")).expect("Could not load v_channel").to_luma8()); | ||
| world.channel_r = Some(image::open(image.clone().replace(".png", "_r_channel.png")).expect("Could not load r_channel").to_luma8()); | ||
| world.channel_g = Some(image::open(image.clone().replace(".png", "_g_channel.png")).expect("Could not load g_channel").to_luma8()); | ||
| world.channel_b = Some(image::open(image.clone().replace(".png", "_b_channel.png")).expect("Could not load b_channel").to_luma8()); | ||
| } | ||
|
|
||
| #[cfg(feature = "yuv_compare")] | ||
| #[when(expr = "comparing yuv channels")] | ||
| fn decompose_yuv(world: &mut SplitWorld) { | ||
| use image_compare::utils::Decompose; | ||
|
|
||
| let [channel_y, channel_u, channel_v] = world.image.as_ref().unwrap().to_rgb8().split_to_yuv(); | ||
| let y_comp = image_compare::gray_similarity_structure(&Algorithm::RootMeanSquared, &channel_y, world.channel_y.as_ref().unwrap()).expect("RMS Gray compare error").score == 1.0; | ||
| let u_comp = image_compare::gray_similarity_structure(&Algorithm::RootMeanSquared, &channel_u, world.channel_u.as_ref().unwrap()).expect("RMS Gray compare error").score == 1.0; | ||
| let v_comp = image_compare::gray_similarity_structure(&Algorithm::RootMeanSquared, &channel_v, world.channel_v.as_ref().unwrap()).expect("RMS Gray compare error").score == 1.0; | ||
|
|
||
| world.success = Some(y_comp && u_comp && v_comp); | ||
| } | ||
|
|
||
| #[cfg(feature = "yuv_compare")] | ||
| #[when(expr = "comparing rgb channels")] | ||
| fn decompose_rgb(world: &mut SplitWorld) { | ||
| use image_compare::utils::Decompose; | ||
|
|
||
| let [channel_r, channel_g, channel_b] = world.image.as_ref().unwrap().to_rgb8().split_channels(); | ||
| let r_comp = image_compare::gray_similarity_structure(&Algorithm::RootMeanSquared, &channel_r, world.channel_r.as_ref().unwrap()).expect("RMS Gray compare error").score == 1.0; | ||
| let g_comp = image_compare::gray_similarity_structure(&Algorithm::RootMeanSquared, &channel_g, world.channel_g.as_ref().unwrap()).expect("RMS Gray compare error").score == 1.0; | ||
| let b_comp = image_compare::gray_similarity_structure(&Algorithm::RootMeanSquared, &channel_b, world.channel_b.as_ref().unwrap()).expect("RMS Gray compare error").score == 1.0; | ||
|
|
||
| world.success = Some(r_comp && g_comp && b_comp); | ||
| } | ||
|
|
||
| #[cfg(feature = "yuv_compare")] | ||
| #[then(expr = "check split success")] | ||
| fn check_success(world: &mut SplitWorld) { | ||
| assert!(world.success.unwrap() == true); | ||
| } | ||
|
|
||
|
|
||
| #[tokio::main] | ||
| async fn main() { | ||
| #[cfg(feature = "yuv_compare")] | ||
| SplitWorld::run("tests/features/decompose.feature").await; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.