tezvyn:

Image gradients, Sobel, and Canny

AI-drafted, machine-checkedSource: interviewbeginner
WHAT IT TESTS

edge-detection foundations.

OUTLINE

the gradient measures local intensity change in x and y; Sobel approximates it via convolution kernels; Canny uses gradient magnitude and direction plus non-max suppression and hysteresis.

WHAT THIS TESTS The interviewer wants the link from calculus to practical edge detection: gradients as derivatives, an operator that estimates them, and the multi-stage pipeline that turns them into clean edges.

A GOOD ANSWER COVERS An image gradient is the vector of partial derivatives of pixel intensity with respect to x and y. Its magnitude tells you how rapidly brightness changes at a point, large at edges, near zero in flat areas, and its direction points in the direction of steepest change, perpendicular to an edge. The Sobel operator estimates these derivatives by convolving the image with two small 3 by 3 kernels, one for the horizontal derivative and one for the vertical, each combining differencing with light smoothing to suppress noise.

COMMON WRONG ANSWERS Saying the gradient is a single number rather than a vector with magnitude and direction. Treating Sobel and Canny as interchangeable. Omitting non-maximum suppression or the hysteresis thresholding that distinguishes Canny.

LIKELY FOLLOW-UPS Why does Canny use two thresholds. What does non-maximum suppression accomplish. Why smooth before differentiating.

ONE CONCRETE EXAMPLE To find edges in a photo you first run Sobel to get the horizontal and vertical derivatives at every pixel, then combine them into gradient magnitude and direction. A raw magnitude image already highlights edges but they are thick and noisy. Canny refines this in stages. It first applies a Gaussian blur so noise does not create spurious edges. It computes the Sobel gradients. It then performs non-maximum suppression, keeping only pixels that are local maxima along the gradient direction, which thins fat ridges down to one-pixel-wide lines. Finally it applies hysteresis with a high and a low threshold: pixels above the high threshold are definite edges, pixels above the low threshold are kept only if they connect to a definite edge, which links broken contours while rejecting isolated weak responses. The result is clean, thin, connected edges. So Sobel is one building block, the gradient estimator, while Canny is the full pipeline that uses gradients plus suppression and hysteresis to produce high-quality edges.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.