Skip to main content

Crate image_conv

Crate image_conv 

Source
Expand description

§image-conv — High-Performance Image Convolution

This library applies convolution filters to images. A convolution slides a small matrix (the kernel, or filter) over every pixel of the image, multiplying overlapping values and summing the results to produce each output pixel.

§Architecture

┌──────────────┐     ┌─────────────────────┐     ┌──────────────┐
│  Input Image  │────▶│  convolution()       │────▶│ Output Image │
│ (PhotonImage) │     │  ├─ try_separable()  │     │ (PhotonImage)│
└──────────────┘     │  │  ├─ Y: separable   │     └──────────────┘
                     │  │  └─ N: 2D fallback │
┌──────────────┐     │  ├─ padding           │
│  Filter       │────▶│  └─ output dimensions│
└──────────────┘     └─────────────────────┘

The Filter struct holds a convolution kernel (also called a “mask” or “window”). convolution() auto-detects whether the kernel is separable — if so, it decomposes the 2D convolution into two 1D passes for a major speedup (e.g. a 15×15 Gaussian goes from O(225) to O(30) per pixel, ~7.5× faster).

§Example

use image_conv::conv;
use image_conv::{Filter, PaddingType};
use photon_rs::native::{open_image, save_image};

fn main() {
    let mut img = open_image("img.jpg").expect("No such file found");

    // Sobel-X edge detection kernel (3×3)
    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);

    // Automatically detected as separable: col=[1,2,1] × row=[1,0,-1]
    let img_conv = conv::convolution(&img, filter, 1, PaddingType::UNIFORM(1));
    save_image(img_conv, "img_conv.jpg");
}

Modules§

conv
Image Convolution Engine

Structs§

Filter
A 2D convolution kernel (filter / mask / window).

Enums§

PaddingType
Specifies how border pixels are handled during convolution.

Functions§

dynamic_to_photon
Converts an image::DynamicImage into a PhotonImage.
photon_to_dynamic
Converts a PhotonImage (photon-rs native format) into an image::DynamicImage (image crate format).