Skip to content

Commit

Permalink
Merge pull request #9 from printify/sum-fix
Browse files Browse the repository at this point in the history
fix: Calculate sum as f64 for images above 4096x4096
  • Loading branch information
ChrisRega committed Apr 4, 2024
2 parents 21dcda9 + 5f1b81a commit cfef8d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ fn merge_similarity_channels_yuva(
},
);

let score = deviation.iter().sum::<f32>() as f64 / deviation.len() as f64;
let score = deviation.iter().map(|s| *s as f64).sum::<f64>() / deviation.len() as f64;

Similarity {
image: image.into(),
score,
Expand Down Expand Up @@ -84,7 +85,7 @@ fn merge_similarity_channels_yuv(input: &[GraySimilarityImage; 3]) -> Similarity
*rgb = Rgb([1. - y, 1. - u, 1. - v]);
});

let score = deviation.iter().sum::<f32>() as f64 / deviation.len() as f64;
let score = deviation.iter().map(|s| *s as f64).sum::<f64>() / deviation.len() as f64;
Similarity {
image: image.into(),
score,
Expand Down
8 changes: 4 additions & 4 deletions tests/features/hybrid_rgb.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Then the similarity score is <result>
Examples:
| compare_image | result |
| tests/data/pad_gaprao.png | 1.0 |
| tests/data/pad_gaprao_lighter.png | 0.948974609375 |
| tests/data/pad_gaprao_noise.png | 0.13009302571614584 |
| tests/data/pad_gaprao_gray_inverted.png | 3.256663878758748e-5 |
| tests/data/pad_gaprao_color_filters.png | 0.9884529947916667 |
| 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 |
18 changes: 9 additions & 9 deletions tests/features/hybrid_rgba.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ Feature: RGBA image comparison using hybrid mode - MSSIM for for Y, Alpha channe
Given the images 'tests/data/100/hand_white.png' and 'tests/data/100/typed_alpha.png' are loaded
When comparing the images using the hybrid mode as rgba
Then the rgba similarity image matches 'tests/data/100/diff_100_hand_alpha.png'
And the similarity score is 0.00635866355150938
And the similarity score is 0.006358610363005692

Scenario: Comparing two images where one is transparent in front of black background
Given the images 'tests/data/100/hand_white.png' and 'tests/data/100/typed_alpha.png' are loaded
When comparing the images using the blended hybrid mode with 'black' background
Then the similarity score is 0.007445383816957474
Then the similarity score is 0.007447309291571148

Scenario: Comparing two images where one is transparent in front of white background
Given the images 'tests/data/100/hand_white.png' and 'tests/data/100/typed_alpha.png' are loaded
When comparing the images using the blended hybrid mode with 'white' background
Then the similarity score is 0.6302585601806641
Then the similarity score is 0.6303176177525529



Expand All @@ -28,7 +28,7 @@ Feature: RGBA image comparison using hybrid mode - MSSIM for for Y, Alpha channe
Given the images 'tests/data/100/typed_alpha.png' and 'tests/data/100/typed_color_changed.png' are loaded
When comparing the images using the hybrid mode as rgba
Then the rgba similarity image matches 'tests/data/100/diff_100_typed_colors.png'
And the similarity score is 0.9748366475105286
And the similarity score is 0.9748343863750435

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
Expand All @@ -38,8 +38,8 @@ Feature: RGBA image comparison using hybrid mode - MSSIM for for Y, Alpha channe
Examples:
| compare_image | result |
| tests/data/pad_gaprao.png | 1.0 |
| tests/data/pad_gaprao_lighter.png | 0.948974609375 |
| tests/data/pad_gaprao_noise.png | 0.13009302571614584 |
| tests/data/pad_gaprao_gray_inverted.png | 3.256663878758748e-5 |
| tests/data/pad_gaprao_color_filters.png | 0.9884529947916667 |
| tests/data/pad_gaprao_alpha.png | 0.9541552734375 |
| 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 |
| tests/data/pad_gaprao_alpha.png | 0.9540830736098154 |

0 comments on commit cfef8d1

Please sign in to comment.