kornia/kornia-rs

[Feature]: Add Hough Line Transform (and Canny edge detection) to kornia-imgproc

Open

#847 opened on Mar 25, 2026

View on GitHub
 (7 comments) (0 reactions) (1 assignee)Rust (188 forks)auto 404
enhancementhelp wantedtriage

Repository metrics

Stars
 (675 stars)
PR merge metrics
 (PR metrics pending)

Description

🚀 Feature Description

Add a Hough Line Transform implementation to kornia-imgproc for detecting lines in binary/edge images. This includes accumulator-based voting with precomputed sin/cos tables and peak extraction. A Canny edge detector is also proposed as a natural companion, building on the existing spatial_gradient_float (Sobel) by adding non-maximum suppression and double-threshold hysteresis.

📂 Feature Category

Image Processing

💡 Motivation

There is currently no native line detection capability in kornia-rs. Anyone building a detection pipeline that requires line detection has to either implement it from scratch or fall back to OpenCV bindings, which defeats the purpose of a pure-Rust computer vision stack. This gap also means there's no clean edge-to-lines pipeline available natively. Since kornia-imgproc already provides Sobel gradients via spatial_gradient_float, adding Canny + Hough Lines would complete a fundamental CV workflow entirely within the library.

💭 Proposed Solution

Expose a public API along these lines:

rustpub fn hough_lines<A: ImageAllocator>(
    edge_map: &Image<u8, 1, A>,
    threshold: u32,
    rho_resolution: f64,
    theta_resolution: f64,
) -> Vec<Line>

Implementation details:

Precomputed sin/cos lookup tables for the theta range Accumulator matrix with voting from edge pixels Peak extraction above the given threshold A Line struct representing (rho, theta) parameterization

Canny edge detector (companion):

Non-maximum suppression on gradient magnitude/direction (from existing Sobel) Double-threshold hysteresis for edge linking Output: binary edge map suitable as input to hough_lines

📚 Library Reference

  1. OpenCV: cv::HoughLines and cv::Canny — the standard reference implementations in C++ (OpenCV docs)
  2. Original paper: Duda, R.O. and Hart, P.E., "Use of the Hough Transformation to Detect Lines and Curves in Pictures," Communications of the ACM, 1972
  3. Canny: J. Canny, "A Computational Approach to Edge Detection," IEEE TPAMI, 1986

🔄 Alternatives Considered

  1. Using OpenCV bindings (e.g., opencv-rust): Works but introduces a heavy C++ dependency and undermines the goal of a pure-Rust CV stack.
  2. Probabilistic Hough Transform (HoughLinesP): Could be added as a follow-up; the standard Hough is a cleaner starting point.
  3. Third-party Rust crates: No well-maintained, production-quality Hough implementation currently exists in the Rust ecosystem for this use case.

🎯 Use Cases

  1. Document processing: Detecting ruled lines, table borders, and document edges for deskewing or layout analysis.
  2. Lane detection: Autonomous driving and ADAS pipelines that need line features from road imagery.
  3. Industrial inspection: Detecting straight edges in manufactured parts for quality control.
  4. General CV pipelines: Any workflow that needs a native Rust edge → lines pipeline without leaving the kornia-rs ecosystem.

📝 Additional Context

A working CPU implementation already exists and is ready to be upstreamed. The implementation uses precomputed sin/cos tables for performance and a standard accumulator-voting approach. This pairs naturally with the existing Sobel support (spatial_gradient_float), so adding Canny on top would give kornia-rs a complete edge-to-lines pipeline with no external dependencies.

🤝 Contribution Intent

  • I plan to submit a PR to implement this feature
  • I'm requesting this feature but not planning to implement it

Contributor guide