Edge detection
≈ 7 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
Edge detection includes a variety of mathematical methods that aim at identifying edges, defined as curves in a digital image at which the image brightness changes sharply or, more formally, has discontinuities. The same problem of finding discontinuities in one-dimensional signals is known as step detection and the problem of finding signal discontinuities over time is known as change detection. Edge detection is a fundamental tool in image processing, machine vision and computer vision, particularly in the areas of feature detection and feature extraction.
Edge detection includes a variety of mathematical methods that aim at identifying edges, defined as curves in a digital image at which the image brightness changes sharply or, more formally, has discontinuities. The same problem of finding discontinuities in one-dimensional signals is known as step detection and the problem of finding signal discontinuities over time is known as change detection. Edge detection is a fundamental tool in image processing, machine vision and computer vision, particularly in the areas of feature detection and feature extraction. Thus, a one-dimensional image f that has exactly one edge placed at x = 0 may be modeled as: f(x) = \frac{I_r - I_\ell}{2} \left( \operatorname{erf}\left(\frac{x}{\sqrt{2}\sigma}\right) + 1\right) + I_\ell. At the left side of the edge, the intensity is I_\ell = \lim_{x \rightarrow -\infty} f(x) , and right of the edge it is I_r = \lim_{x \rightarrow \infty} f(x) . The scale parameter \sigma is called the blur scale of the edge. Ideally this scale parameter should be adjusted based on the quality of image to avoid destroying true edges of the image. L_x(x, y) & = -\frac 1 2 L(x-1, y) + 0 \cdot L(x, y) + \frac 1 2 \cdot L(x+1, y) \\[8pt] L_y(x, y) & = -\frac1 2 L(x, y-1) + 0 \cdot L(x, y) + \frac 1 2 \cdot L(x, y+1), \end{align} corresponding to the application of the following filter masks to the image data: L_y = \begin{bmatrix} +1/2 & 0 & -1/2 \end{bmatrix} L \quad \text{and} \quad L_x = \begin{bmatrix} +1/2 \\ 0 \\ -1/2 \end{bmatrix} L. The well-known and earlier Sobel operator is based on the following filters: L_y = \begin{bmatrix} +1 & 0 & -1 \\ +2 & 0 & -2 \\ +1 & 0 & -1 \end{bmatrix} L \quad \text{and} \quad L_x = \begin{bmatrix} +1 & +2 & +1 \\ 0 & 0 & 0 \\ -1 & -2 & -1 \end{bmatrix} L. Given such estimates of first-order image derivatives, the gradient magnitude is then computed as: |\nabla L| = \sqrt{ L_x^2 + L_y^2} while the gradient orientation can be estimated as \theta = \operatorname{atan2}(L_y, L_x). Other first-order difference operators for estimating image gradient have been proposed in the Prewitt operator, Roberts cross, Kayyali operator and Frei–Chen operator. It is possible to extend filters dimension to avoid the issue of recognizing edge in low SNR image. The cost of this operation is loss in terms of resolution. Examples are Extended Prewitt 7×7. \partial_v(L_v) = 0 while the second-order directional derivative in the v -direction of L_v should be negative, i.e., \partial_{vv}(L_v) \leq 0. Written out as an explicit expression in terms of local partial derivatives L_x, L_y, \ldots , L_{yyy} , this edge definition can be expressed as the zero-crossing curves of the differential invariant L_v^2 L_{vv} = L_x^2 \, L_{xx} + 2 \, L_x \, L_y \, L_{xy} + L_y^2 \, L_{yy} = 0, that satisfies a sign-condition on the following differential invariant L_v^3 L_{vvv} = L_x^3 \, L_{xxx} + 3 \, L_x^2 \, L_y \, L_{xxy} + 3 \, L_x \, L_y^2 \, L_{xyy} + L_y^3 \, L_{yyy} \leq 0 where L_x, L_y, \ldots , L_{yyy} denote partial derivatives computed from a scale space representation L obtained by smoothing the original image with a Gaussian kernel. In this way, the edges will be automatically obtained as continuous curves with sub-pixel accuracy. Hysteresis thresholding can also be applied to these differential and subpixel edge segments. In practice, first-order derivative approximations can be computed by central differences as described above, while second-order derivatives can be computed from the scale space representation L according to: \begin{align} L_{xx}(x, y) & = L(x-1, y) - 2 L(x, y) + L(x+1, y), \\[6pt] L_{xy}(x, y) & = \frac 1 4 (L(x-1, y-1) - L(x-1, y+1) - L(x+1, y-1) + L(x+1, y+1)), \\[6pt] L_{yy}(x, y) & = L(x, y-1) - 2 L(x, y) + L(x, y+1). \end{align} corresponding to the following filter masks: L_{xx} = \begin{bmatrix} 1 & -2 & 1 \end{bmatrix} L \quad \text{and} \quad L_{xy} = \begin{bmatrix} -1/4 & 0 & 1/4 \\ 0 & 0 & 0\\ 1/4 & 0 & -1/4 \end{bmatrix} L \quad \text{and} \quad L_{yy} = \begin{bmatrix} 1 \\ -2 \\ 1 \end{bmatrix} L. Higher-order derivatives for the third-order sign condition can be obtained in an analogous fashion. % MATLAB code for prewitt % operator edge detection k = imread("logo.png"); k = rgb2gray(k); k1 = double(k); p_msk = [-1 0 1; -1 0 1; -1 0 1]; kx = conv2(k1, p_msk, 'same'); ky = conv2(k1, p_msk', 'same'); ked = sqrt(kx.^2 + ky.^2); % display the images. imtool(k,[]); % display the edge detection along x-axis. imtool(abs(kx), []); % display the edge detection along y-axis. imtool(abs(ky),[]); % display the full edge detection. imtool(abs(ked),[]); % Scharr operator -> edge detection k = imread("logo.png"); k = rgb2gray(k); k1 = double(k); s_msk = [-3 0 3; -10 0 10; -3 0 3]; kx = conv2(k1, s_msk, 'same'); ky = conv2(k1, s_msk', 'same'); ked = sqrt(kx.^2 + ky.^2); % display the images. imtool(k,[]); % display the edge detection along x-axis. imtool(abs(kx), []); % display the edge detection along y-axis. imtool(abs(ky), []); % display the full edge detection. imtool(abs(ked), []); % MATLAB code for Sobel operator % edge detection k = imread("logo.png"); k = rgb2gray(k); k1 = double(k); s_msk = [-1 0 1; -2 0 2; -1 0 1]; kx = conv2(k1, s_msk, 'same'); ky = conv2(k1, s_msk', 'same'); ked = sqrt(kx.^2 + ky.^2); % display the images. imtool(k,[]); % display the edge detection along x-axis. imtool(abs(kx), []); % display the edge detection along y-axis. imtool(abs(ky), []); % display the full edge detection. imtool(abs(ked), []);
See also
Edge-preserving filtering Feature detection (computer vision) for other low-level feature detectors Image derivative Gabor filter Image noise reduction Kirsch operator for edge detection in the compass directions Ridge detection for relations between edge detectors and ridge detectors Log Gabor filter Phase stretch transform
References
Further reading
Entry on edge detection in Encyclopedia of Computer Science and Engineering Edge Detection using FPGA A-contrario line segment detection with code and on-line demonstration Edge detection using MATLAB Subpixel edge detection using Matlab Image Tools Effects - Edgedetect Edge Detection for Image Processing
Text derived from https://en.wikipedia.org/w/index.php?oldid=1373059615 under CC BY-SA 4.0; modifications have been made.