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 it works
Canny finds edges in stages and uses hysteresis to decide which to keep. Any pixel whose gradient exceeds the high threshold is a definite edge. Any pixel above the low threshold is kept only if it connects to a definite edge — this links genuine contours while rejecting isolated noise. The aperture size sets the Sobel kernel for the gradient computation (3 is standard; larger smooths first), and L2 gradient swaps the fast L1 approximation for a more accurate magnitude. The map this produces is what ControlNet locks the generation’s structure onto.
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.