initial commit

This commit is contained in:
2022-11-10 00:41:06 +01:00
commit 0eccde4b18
9 changed files with 628 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
use image::GenericImageView;
pub trait Descriptor {
fn info(&self) -> String {
"Descriptor".to_string()
}
fn describe(&self, img: image::DynamicImage) -> u64;
}
pub struct Median;
impl Descriptor for Median {
fn describe(&self, img: image::DynamicImage) -> u64 {
let mut median: u64 = 0; //Average for now while i figure out sorting in rust
let img = img.grayscale().thumbnail_exact(8, 8);
for (_, _, pix) in img.pixels() {
median += pix[0] as u64;
}
let median: u8 = (median/64) as u8;
let mut mask: u64 = 0;
img.save("debug.png").unwrap();
for (_, _, pix) in img.pixels() {
if pix[0] > median {
mask += 1;
}
mask = mask << 1;
}
mask
}
}
+13
View File
@@ -0,0 +1,13 @@
use descriptors::{Descriptor, Median};
pub mod descriptors;
fn main() {
let desc = Median;
let img0 = image::open("img/meowl.jpg").unwrap();
let img1 = image::open("img/nyameowl.jpg").unwrap();
let img2 = image::open("img/armmeowl.jpg").unwrap();
println!("{:#x}", desc.describe(img0));
println!("{:#x}", desc.describe(img1));
println!("{:#x}", desc.describe(img2));
}