Skip to content

Commit

Permalink
Reworked return value structure by making the diff image mandatory. B…
Browse files Browse the repository at this point in the history
…umped version to RC1
  • Loading branch information
ChrisRega committed Apr 30, 2023
1 parent 5f61793 commit 4e82aef
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/colorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct Similarity {
/// - RMS will be between 0. for all-white vs all-black and 1.0 for identical
/// - SSIM usually is near 1. for similar, near 0. for different but can take on negative values for negative covariances
/// - Hybrid mode will be inverse: 0. means no difference, 1.0 is maximum difference. For details see [`crate::hybrid::rgb_hybrid_compare`]
pub image: Option<SimilarityImage>,
pub image: SimilarityImage,
/// the average score of the image
pub score: f64,
}
4 changes: 2 additions & 2 deletions src/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn merge_similarity_channels_yuva(

let score = deviation.iter().sum::<f32>() as f64 / deviation.len() as f64;
Similarity {
image: Some(image.into()),
image: image.into(),
score,
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ fn merge_similarity_channels_yuv(input: &[GraySimilarityImage; 3]) -> Similarity

let score = deviation.iter().sum::<f32>() as f64 / deviation.len() as f64;
Similarity {
image: Some(image.into()),
image: image.into(),
score,
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
//! let image_two = image::open("image2.png").expect("Could not find test-image").into_rgba8();
//! let result = image_compare::rgba_hybrid_compare(&image_one, &image_two).expect("Images had different dimensions");
//! if result.score < 0.95 {
//! //we can unwrap here since hybrid compare always produces the result image
//! let diff_img = result.image.unwrap().to_color_map();
//! let diff_img = result.image.to_color_map();
//! diff_img.save("diff_image.png").expect("Could not save diff image");
//! }
//! ```
Expand Down Expand Up @@ -101,6 +100,9 @@ pub mod prelude {
CalculationFailed(String),
}

pub use crate::colorization::GraySimilarityImage;
pub use crate::colorization::RGBASimilarityImage;
pub use crate::colorization::RGBSimilarityImage;
pub use crate::colorization::Similarity;
}

Expand Down Expand Up @@ -138,7 +140,7 @@ pub fn gray_similarity_structure(
Algorithm::MSSIMSimple => ssim_simple(first, second),
}
.map(|(score, i)| Similarity {
image: Some(i.into()),
image: i.into(),
score,
})
}
Expand Down Expand Up @@ -189,7 +191,7 @@ pub fn rgb_similarity_structure(
let image = utils::merge_similarity_channels(&input.try_into().unwrap());
let score = results.iter().map(|(s, _)| *s).fold(1., f64::min);
Ok(Similarity {
image: Some(image.into()),
image: image.into(),
score,
})
}
Expand Down
8 changes: 1 addition & 7 deletions tests/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn compare_hist_corr(world: &mut CompareWorld, metric: String) {
&world.second.as_ref().unwrap().clone().into_luma8(),
)
.expect("Error comparing the two images!"),
image: None,
image: GraySimilarityImage::new(0, 0).into(),
});
}

Expand Down Expand Up @@ -149,8 +149,6 @@ fn check_result_image(world: &mut CompareWorld, reference: String) {
.as_ref()
.unwrap()
.image
.as_ref()
.unwrap()
.to_color_map()
.into_luma8();
let image_one = image::open(reference)
Expand All @@ -171,8 +169,6 @@ fn check_result_image_rgba(world: &mut CompareWorld, reference: String) {
.as_ref()
.unwrap()
.image
.as_ref()
.unwrap()
.to_color_map()
.into_rgba8();
let image_one = image::open(reference)
Expand All @@ -193,8 +189,6 @@ fn check_result_image_rgb(world: &mut CompareWorld, reference: String) {
.as_ref()
.unwrap()
.image
.as_ref()
.unwrap()
.to_color_map()
.into_rgb8();
let image_one = image::open(reference)
Expand Down

0 comments on commit 4e82aef

Please sign in to comment.