#[cfg(feature = "rayon")]
use super::filter_clamped_parallel;
use super::{filter_clamped, gaussian_blur_f32};
use crate::{
definitions::{Clamp, Image},
kernel::Kernel,
map::{map_pixels2, map_subpixels},
};
use image::{GrayImage, Luma};
#[must_use = "the function does not modify the original image"]
pub fn sharpen3x3(image: &GrayImage) -> GrayImage {
let identity_minus_laplacian = Kernel::new(&[0, -1, 0, -1, 5, -1, 0, -1, 0], 3, 3);
filter_clamped(image, identity_minus_laplacian)
}
#[must_use = "the function does not modify the original image"]
#[cfg(feature = "rayon")]
#[doc = generate_parallel_doc_comment!("sharpen3x3")]
pub fn sharpen3x3_parallel(image: &GrayImage) -> GrayImage {
let identity_minus_laplacian = Kernel::new(&[0, -1, 0, -1, 5, -1, 0, -1, 0], 3, 3);
filter_clamped_parallel(image, identity_minus_laplacian)
}
#[must_use = "the function does not modify the original image"]
pub fn sharpen_gaussian(image: &GrayImage, sigma: f32, amount: f32) -> GrayImage {
let image = map_subpixels(image, |x| x as f32);
let smooth: Image<Luma<f32>> = gaussian_blur_f32(&image, sigma);
map_pixels2(&image, &smooth, |p, q| {
let v = (1.0 + amount) * p[0] - amount * q[0];
Luma([<u8 as Clamp<f32>>::clamp(v)])
})
}