Skip to content

Commit

Permalink
Add parallelized sharpen3x3
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed May 19, 2024
1 parent 8f61014 commit 5167cac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ where

/// Returns 2d correlation of an image with a row-major kernel. Intermediate calculations are
/// performed at type K, and the results clamped to subpixel type S. Pads by continuity.
///
/// A parallelized version of this function exists with [`filter_clamped_parallel`] when
/// the crate `rayon` feature is enabled.
pub fn filter_clamped<P, K, S>(image: &Image<P>, kernel: Kernel<K>) -> Image<ChannelMap<P, S>>
where
P::Subpixel: Into<K>,
Expand Down
12 changes: 12 additions & 0 deletions src/filter/sharpen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(feature = "rayon")]
use super::filter_clamped_parallel;
use super::{filter_clamped, gaussian_blur_f32};
use crate::{
definitions::{Clamp, Image},
Expand All @@ -13,6 +15,16 @@ pub fn sharpen3x3(image: &GrayImage) -> GrayImage {
filter_clamped(image, identity_minus_laplacian)
}

/// Sharpens a grayscale image by applying a 3x3 approximation to the Laplacian.
/// This version uses rayon to parallelize the computation.
#[must_use = "the function does not modify the original image"]
#[cfg(feature = "rayon")]
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
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)
}

/// Sharpens a grayscale image using a Gaussian as a low-pass filter.
///
/// * `sigma` is the standard deviation of the Gaussian filter used.
Expand Down

0 comments on commit 5167cac

Please sign in to comment.