diff --git a/src/descriptors/dct.rs b/src/descriptors/dct.rs index 3d5e06d..adbc140 100644 --- a/src/descriptors/dct.rs +++ b/src/descriptors/dct.rs @@ -29,7 +29,6 @@ impl DCT { 50..=100 => 200.0 - 2.0*quality as f32, _ => 100.0 // Invalid input: set to base quality }; - //for i in 0..64 { for (_, cell) in quantization_matrix.iter_mut().enumerate() { *cell = ((scalar * *cell as f32 + 50.0) / 100.0).floor() as u8; if *cell == 0 { @@ -69,9 +68,9 @@ impl DCT { } } dct_values - } + } - fn idct(&self, dct_values: [f64; 64]) -> [u8; 64] { + fn idct(&self, dct_values: [f64; 64]) -> [u8; 64] { let mut reconstructed: [u8; 64] = [0; 64]; //for k in 0..64 { for (k, item) in reconstructed.iter_mut().enumerate() { @@ -216,4 +215,4 @@ impl Descriptor for DCT { // TODO: Do something with these last 8 bits. mask } -} \ No newline at end of file +} diff --git a/src/mutators/mod.rs b/src/mutators/mod.rs index fbc3247..8c2f659 100644 --- a/src/mutators/mod.rs +++ b/src/mutators/mod.rs @@ -1,5 +1,8 @@ //! Mutators that can be used to mutate an image. //! These mutated images can be used as a "near copy" +use image::{Rgb, Rgba}; +use imageproc::definitions::Image; +use imageproc::geometric_transformations::*; pub trait Mutator { /// Name/description of the mutator @@ -15,7 +18,7 @@ pub trait Mutator { fn mutate(&self, img: &image::DynamicImage) -> image::DynamicImage; } -/// Horizontal flip/mirror +/// Horizontal mirror pub struct Flip; impl Mutator for Flip { fn info(&self) -> String { @@ -29,7 +32,7 @@ impl Mutator for Flip { } } -/// Slight hue-shift +/// Hue shift pub struct Hue; impl Mutator for Hue { fn info(&self) -> String { @@ -43,7 +46,7 @@ impl Mutator for Hue { } } -/// Slight sharpen (unsharp mask) +/// Unsharp mask pub struct Sharp; impl Mutator for Sharp { fn info(&self) -> String { @@ -57,7 +60,6 @@ impl Mutator for Sharp { } } -/// Slight blur pub struct Blur; impl Mutator for Blur { fn info(&self) -> String { @@ -71,6 +73,34 @@ impl Mutator for Blur { } } +pub struct BlurSharp; +impl Mutator for BlurSharp { + fn info(&self) -> String { + "Blur and sharpen".to_string() + } + fn tag(&self) -> String { + ".blsh.".to_string() + } + fn mutate(&self, img: &image::DynamicImage) -> image::DynamicImage { + img.blur(1.5).unsharpen(1.5, 20) + } +} + +pub struct RotateCrop; +impl Mutator for RotateCrop { + fn info(&self) -> String { + "Rotate and crop".to_string() + } + fn tag(&self) -> String { + ".rcrop.".to_string() + } + fn mutate(&self, img: &image::DynamicImage) -> image::DynamicImage { + let img: Image> = img.to_rgb8(); + let default = *img.get_pixel(0, 0); + image::DynamicImage::ImageRgb8(rotate_about_center(&img, 0.1, Interpolation::Bicubic, default)) + } +} + pub fn get_all_mutators() -> Vec> { let mutators: Vec> = //Vec::with_capacity(4); vec![