Skip to main content

convolution

Function convolution 

Source
pub fn convolution(
    img: &PhotonImage,
    filter: Filter,
    stride: u32,
    padding: PaddingType,
) -> PhotonImage
Expand description

Applies convolution to an image using the given filter.

Each path (separable 1D and standard 2D) is parallelised across output rows via rayon — no data dependencies between rows, trivially parallel.

§Speedup Examples

KernelSizeSequentialRayon (8 cores)
Gauss7×761 ms~8 ms
Gauss15×1594 ms~12 ms
Laplacian3×347 ms~6 ms

§Example

use image_conv::conv;
use image_conv::{Filter, PaddingType};

let img = photon_rs::native::open_image("img.jpg").expect("No such file found");
let sobel_x: Vec<f32> = vec![1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0];
let filter = Filter::from(sobel_x, 3, 3);
let img_conv = conv::convolution(&img, filter, 1, PaddingType::UNIFORM(1));