-
-
Notifications
You must be signed in to change notification settings - Fork 174
Description
π Feature Description
Add a Canny edge detection function to kornia-imgproc. Canny is an edge detection algorithm that produces clean 1-pixel-wide binary edge maps from grayscale images.
kornia-rs already has the two main building blocks (Gaussian blur and Sobel) for this algorithm.
π Feature Category
Rust Core Library
π‘ Motivation
Canny is one of the most widely used edge detection algorithms in computer vision. Having Canny would give new features to kornia-rs that depend on edge detection as input. Right now Kornia already has kornia.filters.Canny, but there's no Rust equivalent in kornia-rs yet.
Also, it is a natural addition to kornia-rs's current image processing pipeline. It can be built directly based on the existing Gaussian blur and Sobel operators.
π Proposed Solution
Add canny.rs inside crates/kornia-imgproc/src. The signature is below:
pub fn canny<A1, A2, A3>(
src: &Image<u8, 1, A1>,
magnitude: &mut Image<f32, 1, A2>,
edges: &mut Image<u8, 1, A3>,
low_threshold: f32,
high_threshold: f32,
kernel_size: usize,
hysteresis: bool,
) -> Result<(), ImageError>The input is a single-channel u8 grayscale image. The function internally converts to f32 for processing. The edge output is a binary u8 image where edges are 255 and non-edges are 0. The magnitude output is f32 for raw gradient strength.
The implementation follows the standard 5-stage pipeline:
- Gaussian blur (existing
gaussian_blur) - Sobel gradients (existing
separable_filter+sobel_kernel_1d) - Non-maximum suppression along gradient direction
- Double thresholding
- BFS-based hysteresis edge tracking
π Library Reference
The implementation of this feature is basically based on:
- Kornia: https://github.com/kornia/kornia/blob/main/kornia/filters/canny.py
- OpenCV: https://docs.opencv.org/4.x/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de
π Alternatives Considered
No response
π― Use Cases
It will be useful for contour extraction (as kornia-rs already has find_contour), object boundary/edge detection, lane detection, and general feature extraction pipelines.
kornia-rs currently have Sobel gradients, gaussian blur, and binary thresholding. A typical workaround would be to threshold Sobel magnitude.
Here is a comparison between the typical workaround and the demo implementation of canny:
For this image, canny edge detection algorithm works better than sobel threshold method.
π Additional Context
I currently have a working demo implementation.
Happy to submit a PR and continue work on it if approved!
π€ Contribution Intent
- I plan to submit a PR to implement this feature
- I'm requesting this feature but not planning to implement it


