feat: Suzuki and Abe Contour finding implementation#767
feat: Suzuki and Abe Contour finding implementation#767zeel991 wants to merge 11 commits intokornia:mainfrom
Conversation
Review Summary by QodoImplement Suzuki & Abe contour finding with SWAR optimization
WalkthroughsDescription• Implements Suzuki & Abe (1985) border-following algorithm for contour detection • Supports four retrieval modes (External, List, CComp, Tree) with full hierarchy • Includes two approximation modes (None, Simple) for contour point compression • Optimizes scanning with SWAR (Single-Word-At-a-time Read) to skip zero pixels • Provides reusable FindContoursExecutor for repeated processing without allocation • Adds comprehensive benchmarks comparing against OpenCV implementation Diagramflowchart LR
Input["Input Image<br/>u8 pixels"]
Binarize["Binarize &<br/>Virtual Pad"]
Scan["Raster Scan<br/>with SWAR"]
Trace["Trace Border<br/>Suzuki-Abe"]
Approx["Approximate<br/>None/Simple"]
Filter["Filter by<br/>Retrieval Mode"]
Output["ContoursResult<br/>contours + hierarchy"]
Input --> Binarize
Binarize --> Scan
Scan --> Trace
Trace --> Approx
Approx --> Filter
Filter --> Output
File Changes1. crates/kornia-imgproc/src/contours.rs
|
Code Review by Qodo
1. find_countours not implemented
|
There was a problem hiding this comment.
Pull request overview
Adds a new contour-finding feature to kornia-imgproc, implementing the Suzuki & Abe (1985) border-following algorithm and exposing a public find_contours API (plus an executor for reuse), along with benchmarks and unit tests.
Changes:
- Added
contoursmodule export tokornia-imgproc. - Implemented contour tracing, approximation modes, and hierarchy reconstruction with multiple retrieval modes.
- Added Criterion benchmark comparing against OpenCV (behind
opencv_benchfeature).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
crates/kornia-imgproc/src/lib.rs |
Exposes the new contours module from the crate root. |
crates/kornia-imgproc/src/contours.rs |
Implements contour finding, hierarchy modes, reusable executor, and unit tests. |
crates/kornia-imgproc/benches/bench_contours.rs |
Adds benchmarks for contours (kornia vs OpenCV, incl. executor variants). |
crates/kornia-imgproc/Cargo.toml |
Registers the new bench_contours benchmark gated by opencv_bench. |
128×128 — Simple approximation
256×256 — Simple approximation
512×512 — Simple approximation
1024×1024 — Simple approximation
|
|
also please update the |
Added |
|
@sidd-27 @cjpurackal please review this pr and merge it |
|
|
||
| /// Minimum image area in pixels above which binarisation is parallelised via Rayon | ||
| /// Below this threshold the thread-dispatch overhead outweighs the benefit | ||
| const PARALLEL_THRESHOLD: usize = 512 * 512; |
There was a problem hiding this comment.
do you have any benchmark numbers for this choice?
Review SummaryExcellent implementation of Suzuki & Abe contour finding! 🚀 ✅ Strengths:
|
Tysm, I have pushed the recommended fixes also added a test to check them for assurance |
|
could you look into the failing test? dosent seem related to the pr but just in case |
I checked ,its not due to my PR |
sidd-27
left a comment
There was a problem hiding this comment.
i think adding an example would help, lgtm otherwise
should I add it in this PR or raise a separate PR for that? |









📝 Description
Fixes/Relates to: #169
Important:
🛠️ Changes Made
kornia-imgproc): Full implementation of the Suzuki & Abe (1985) border-following algorithm withfind_contoursand a reusableFindContoursExecutor.u64word reads to skip 4 zero pixels at a time, reducing per-pixel overhead in sparse/background regions.External,List,CComp, andTreeretrieval modes with correct parent-child nesting.SimpleandNoneapproximation modes also supported.🧪 How Was This Tested?
test_simple_square_no_approx,test_simple_square_simple_approx,test_hollow_square_external_vs_list,test_isolated_pixel,test_u_shape,test_no_empty_contour_simple_approx,test_many_contours_no_overflow,test_executor_reuse_identical🕵️ AI Usage Disclosure
Check one of the following:
🚦 Checklist
💭 Additional Context
Add any other context or screenshots about the pull request here.