imageproc/filter/
sharpen.rs1use super::{filter3x3, gaussian_blur_f32};
2use crate::{
3 definitions::{Clamp, Image},
4 map::{map_colors2, map_subpixels},
5};
6use image::{GrayImage, Luma};
7
8#[must_use = "the function does not modify the original image"]
10pub fn sharpen3x3(image: &GrayImage) -> GrayImage {
11 let identity_minus_laplacian = [0, -1, 0, -1, 5, -1, 0, -1, 0];
12 filter3x3(image, &identity_minus_laplacian)
13}
14
15#[must_use = "the function does not modify the original image"]
21pub fn sharpen_gaussian(image: &GrayImage, sigma: f32, amount: f32) -> GrayImage {
22 let image = map_subpixels(image, |x| x as f32);
23 let smooth: Image<Luma<f32>> = gaussian_blur_f32(&image, sigma);
24 map_colors2(&image, &smooth, |p, q| {
25 let v = (1.0 + amount) * p[0] - amount * q[0];
26 Luma([<u8 as Clamp<f32>>::clamp(v)])
27 })
28}