Canny Edge Preprocessing Guide

Set Canny low/high thresholds correctly for ControlNet edge detection

Guide to preparing Canny edge maps for ControlNet. Explains low threshold, high threshold, aperture size, and L2 gradient, and recommends settings by image type so your edge map captures the right detail density. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What do the low and high thresholds actually do?

Canny uses hysteresis. Pixels with a gradient above the high threshold are definite edges; pixels above the low threshold are kept only if connected to a definite edge. Raising the high threshold drops weak edges, while lowering the low threshold lets more faint detail through.

Canny edge preprocessing guide

Canny edge detection is the most-used ControlNet preprocessor: it turns a source image into a clean black-and-white edge map that constrains the structure of the generated image. Its output is almost entirely controlled by two numbers — the low and high thresholds — plus the aperture size and the L2 gradient toggle. Get the thresholds wrong and you either lose the composition or trace every speck of noise.

How Canny works under the hood

Canny finds edges in five stages:

  1. Noise reduction — a Gaussian blur smooths the image first, dampening pixel noise before gradient computation.
  2. Gradient calculation — a Sobel operator computes the intensity gradient at each pixel. The aperture size controls how large this kernel is.
  3. Non-maximum suppression — only local maxima along the gradient direction are kept; edges become thin single-pixel lines.
  4. Double threshold — pixels above the high threshold are definite edges; pixels between low and high are “weak” candidates.
  5. Hysteresis — weak pixels adjacent to strong ones are kept; isolated weak pixels are discarded as noise.

The hysteresis step is what makes Canny superior to a simple single-threshold approach: it traces complete edge contours without flooding the map with noise.

Threshold recommendations by source type

Source typeLow thresholdHigh thresholdNotes
Clean line art, sketches30–8080–150Capture every line; noise is not a concern
Portrait photo, smooth skin80–120160–220Balance face edges vs skin texture noise
Landscape / general photo100–150200–300Suppress grass/leaf texture, keep horizon
Architecture, hard edges80–120150–250Fine lines and geometry; less texture noise
Noisy or grainy photo120–180250–350Raise both and use aperture 5 or 7
Product / 3D render50–100100–200Clean source; lower thresholds safe

These are starting points; iterate from the defaults and adjust based on what the map over- or under-represents.

What the aperture size actually changes

The aperture is the Sobel kernel size — the neighbourhood of pixels used to estimate the gradient at each point. Aperture 3 (default) looks at a 3×3 region: fast and fine-grained. Aperture 5 looks at a 5×5 region, effectively pre-smoothing the image before detecting, which is useful for high-resolution photos where small textures produce spurious gradients. Aperture 7 smooths further still and should only be used on very high-resolution or very noisy sources. Most generation-size (512–1024px) images work best with aperture 3.

Tips for the right edge density

  • Match thresholds to source. Line art wants low thresholds (catch every line); busy photos want high thresholds (keep only major contours).
  • Widen the gap for more detail. A bigger spread between low and high (say 50/200) preserves more connected faint edges than a narrow one.
  • Use aperture 5 for noisy images. Larger apertures smooth before detecting, giving cleaner maps from grainy or high-resolution photos.
  • Save L2 gradient for finals. It is slightly slower but produces crisper, more accurate edges when the map quality matters.
  • Preview at generation resolution. A map that looks fine at the source image size can look over-dense or sparse once scaled to the generation dimensions. Check the map at the actual input size ControlNet will receive.
  • Too many edges? Raise both thresholds proportionally — the ratio between them matters as much as the individual values.
  • Too few edges and the composition is lost? Lower the high threshold first; the low threshold controls the sensitivity of the connectivity step.