distance function

This commit is contained in:
2022-11-10 17:33:32 +01:00
parent 0eccde4b18
commit b449855bab
2 changed files with 10 additions and 3 deletions
+3
View File
@@ -5,6 +5,9 @@ pub trait Descriptor {
"Descriptor".to_string() "Descriptor".to_string()
} }
fn describe(&self, img: image::DynamicImage) -> u64; fn describe(&self, img: image::DynamicImage) -> u64;
fn distance(&self, a: u64, b: u64) -> u64 {
(a^b).count_ones().into()
}
} }
pub struct Median; pub struct Median;
+7 -3
View File
@@ -7,7 +7,11 @@ fn main() {
let img0 = image::open("img/meowl.jpg").unwrap(); let img0 = image::open("img/meowl.jpg").unwrap();
let img1 = image::open("img/nyameowl.jpg").unwrap(); let img1 = image::open("img/nyameowl.jpg").unwrap();
let img2 = image::open("img/armmeowl.jpg").unwrap(); let img2 = image::open("img/armmeowl.jpg").unwrap();
println!("{:#x}", desc.describe(img0)); let img0_phash = desc.describe(img0);
println!("{:#x}", desc.describe(img1)); let img1_phash = desc.describe(img1);
println!("{:#x}", desc.describe(img2)); let img2_phash = desc.describe(img2);
println!("{:#x}", img0_phash);
println!("{:#x}", img1_phash);
println!("{:#x}", img2_phash);
println!("meowl and armmeowl are {} different", desc.distance(img0_phash, img2_phash));
} }