Canny edges
Turn image gradients into thin, connected edge chains using two thresholds.
Flat regions and sharp transitions respond very differently.
Smoothing precedes the derivatives. Brighter samples indicate larger local intensity changes.
Non-maximum suppression removes responses on either side of a local ridge, leaving a thin candidate boundary.
Hysteresis starts at strong responses and follows connected weak ones. Isolated weak responses disappear.
Keep strong edges and weak edges connected to them.
Computed teaching example on a 24 × 16 image. Small kernels and simplified settings keep each change visible; use the image laboratory for native OpenCV.
Try it on an image
Experiment at pixel level
Detect edges in grayscale. The two thresholds control weak and strong gradient responses.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Trace object boundaries for geometry, contour extraction, or line detection.
How it works
- 01Measure gradient magnitude and direction.
- 02Suppress responses that are not local maxima across the edge.
- 03Keep strong edges and weak edges connected to them.
strong ≥ high; weak ≥ low survives only if connected
What to tune
threshold1 and threshold2 govern hysteresis. apertureSize controls the derivative kernel; L2gradient selects Euclidean magnitude.
Where it breaks down
Canny does not itself identify objects. Noise, texture and illumination can produce extra boundaries. Apply suitable smoothing before the call.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.