45 lines
1.6 KiB
Rust
45 lines
1.6 KiB
Rust
|
|
use image;
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
let out_path = "/tmp/composite_output.png";
|
||
|
|
let ref_path = "/home/hc/Pictures/_test_images/example3/Example3-mini.png";
|
||
|
|
|
||
|
|
if !std::path::Path::new(out_path).exists() || !std::path::Path::new(ref_path).exists() {
|
||
|
|
println!("Images not found.");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let out_img = image::open(out_path).unwrap().to_rgba8();
|
||
|
|
let ref_img = image::open(ref_path).unwrap().to_rgba8();
|
||
|
|
|
||
|
|
if out_img.width() != ref_img.width() || out_img.height() != ref_img.height() {
|
||
|
|
println!("Dimensions differ: out={}x{}, ref={}x{}", out_img.width(), out_img.height(), ref_img.width(), ref_img.height());
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let mut diffs = Vec::new();
|
||
|
|
for y in 0..out_img.height() {
|
||
|
|
for x in 0..out_img.width() {
|
||
|
|
let p1 = out_img.get_pixel(x, y);
|
||
|
|
let p2 = ref_img.get_pixel(x, y);
|
||
|
|
let dr = (p1[0] as i32 - p2[0] as i32).abs();
|
||
|
|
let dg = (p1[1] as i32 - p2[1] as i32).abs();
|
||
|
|
let db = (p1[2] as i32 - p2[2] as i32).abs();
|
||
|
|
let da = (p1[3] as i32 - p2[3] as i32).abs();
|
||
|
|
let total = dr + dg + db + da;
|
||
|
|
if total > 0 {
|
||
|
|
diffs.push((x, y, p1.0, p2.0, total));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
diffs.sort_by_key(|d| std::cmp::Reverse(d.4));
|
||
|
|
|
||
|
|
println!("Total differing pixels: {} / {}", diffs.len(), out_img.width() * out_img.height());
|
||
|
|
println!("\nTop 50 worst pixels:");
|
||
|
|
for i in 0..50.min(diffs.len()) {
|
||
|
|
let (x, y, p1, p2, total) = diffs[i];
|
||
|
|
println!(" at ({:4}, {:4}): out={:?}, ref={:?}, sum_diff={}", x, y, p1, p2, total);
|
||
|
|
}
|
||
|
|
}
|