Skip to content

Canny edges

Turn image gradients into thin, connected edge chains using two thresholds.

Try it on your image ↓

VISUAL WALKTHROUGHEdges
REFERENCE INPUTIntensity image

Flat regions and sharp transitions respond very differently.

RESULTLink strong and weak edges

Hysteresis starts at strong responses and follows connected weak ones. Isolated weak responses disappear.

STEP 03 / 03

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

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

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.

Input448 × 320
OutputWaiting for a result

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
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Trace object boundaries for geometry, contour extraction, or line detection.

How it works

  1. 01Measure gradient magnitude and direction.
  2. 02Suppress responses that are not local maxima across the edge.
  3. 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.