Quantcast

Documentation Center

  • Trial Software
  • Product Updates

edge

Find edges in intensity image

Syntax

BW = edge(I)
gpuarrayBW = edge(gpuarrayI)
BW = edge(I,'sobel')
BW = edge(I,'sobel',thresh)
BW = edge(I,'sobel',thresh,direction)
BW = edge(I,'sobel',...,options)
[BW,thresh] = edge(I,'sobel',...)
BW = edge(I,'prewitt')
BW = edge(I,'prewitt',thresh)
BW = edge(I,'prewitt',thresh,direction)
[BW,thresh] = edge(I,'prewitt',...)
BW = edge(I,'roberts')
BW = edge(I,'roberts',thresh)
BW = edge(I,'roberts',...,options)
[BW,thresh] = edge(I,'roberts',...)
BW = edge(I,'log')
BW = edge(I,'log',thresh)
BW = edge(I,'log',thresh,sigma)
[BW,thresh] = edge(I,'log',...)
BW = edge(I,'zerocross',thresh,h)
[BW,thresh] = edge(I,'zerocross',...)
BW = edge(I,'canny')
BW = edge(I,'canny',thresh)
BW = edge(I,'canny',thresh,sigma)
[BW,thresh] = edge(I,'canny',...)

Description

BW = edge(I) takes an intensity or a binary image I as its input, and returns a binary image BW of the same size as I, with 1's where the function finds edges in I and 0's elsewhere.

gpuarrayBW = edge(gpuarrayI) performs the edge detection on a GPU. The input image and the output image are gpuArrays. This syntax requires the Parallel Computing Toolbox™.

By default, edge uses the Sobel method to detect edges but the following provides a complete list of all the edge-finding methods supported by this function:

  • The Sobel method finds edges using the Sobel approximation to the derivative. It returns edges at those points where the gradient of I is maximum.

  • The Prewitt method finds edges using the Prewitt approximation to the derivative. It returns edges at those points where the gradient of I is maximum.

  • The Roberts method finds edges using the Roberts approximation to the derivative. It returns edges at those points where the gradient of I is maximum.

  • The Laplacian of Gaussian method finds edges by looking for zero crossings after filtering I with a Laplacian of Gaussian filter.

  • The zero-cross method finds edges by looking for zero crossings after filtering I with a filter you specify.

  • The Canny method finds edges by looking for local maxima of the gradient of I. The gradient is calculated using the derivative of a Gaussian filter. The method uses two thresholds, to detect strong and weak edges, and includes the weak edges in the output only if they are connected to strong edges. This method is therefore less likely than the others to be fooled by noise, and more likely to detect true weak edges.

The parameters you can supply differ depending on the method you specify. If you do not specify a method, edge uses the Sobel method.

Sobel Method

BW = edge(I,'sobel') specifies the Sobel method.

BW = edge(I,'sobel',thresh) specifies the sensitivity threshold for the Sobel method. edge ignores all edges that are not stronger than thresh. If you do not specify thresh, or if thresh is empty ([]), edge chooses the value automatically.

BW = edge(I,'sobel',thresh,direction) specifies the direction of detection for the Sobel method. direction is a string specifying whether to look for 'horizontal' or 'vertical' edges or 'both' (the default).

BW = edge(I,'sobel',...,options) provides an optional string input. String 'nothinning' speeds up the operation of the algorithm by skipping the additional edge thinning stage. By default, or when 'thinning' string is specified, the algorithm applies edge thinning.

[BW,thresh] = edge(I,'sobel',...) returns the threshold value.

Prewitt Method

BW = edge(I,'prewitt') specifies the Prewitt method.

BW = edge(I,'prewitt',thresh) specifies the sensitivity threshold for the Prewitt method. edge ignores all edges that are not stronger than thresh. If you do not specify thresh, or if thresh is empty ([]), edge chooses the value automatically.

BW = edge(I,'prewitt',thresh,direction) specifies the direction of detection for the Prewitt method. direction is a string specifying whether to look for 'horizontal' or 'vertical' edges or 'both' (default).

[BW,thresh] = edge(I,'prewitt',...) returns the threshold value.

Roberts Method

BW = edge(I,'roberts') specifies the Roberts method.

BW = edge(I,'roberts',thresh) specifies the sensitivity threshold for the Roberts method. edge ignores all edges that are not stronger than thresh. If you do not specify thresh, or if thresh is empty ([]), edge chooses the value automatically.

BW = edge(I,'roberts',...,options) where options can be the text string 'thinning' or 'nothinning'. When you specify 'thinning', or don't specify a value, the algorithm applies edge thinning. Specifying the 'nothinning' option can speed up the operation of the algorithm by skipping the additional edge thinning stage.

[BW,thresh] = edge(I,'roberts',...) returns the threshold value.

Laplacian of Gaussian Method

BW = edge(I,'log') specifies the Laplacian of Gaussian method.

BW = edge(I,'log',thresh) specifies the sensitivity threshold for the Laplacian of Gaussian method. edge ignores all edges that are not stronger than thresh. If you do not specify thresh, or if thresh is empty ([]), edge chooses the value automatically. If you specify a threshold of 0, the output image has closed contours, because it includes all the zero crossings in the input image.

BW = edge(I,'log',thresh,sigma) specifies the Laplacian of Gaussian method, using sigma as the standard deviation of the LoG filter. The default sigma is 2; the size of the filter is n-by-n, where n = ceil(sigma*3)*2+1.

[BW,thresh] = edge(I,'log',...) returns the threshold value.

Zero-Cross Method

BW = edge(I,'zerocross',thresh,h) specifies the zero-cross method, using the filter h. thresh is the sensitivity threshold; if the argument is empty ([]), edge chooses the sensitivity threshold automatically. If you specify a threshold of 0, the output image has closed contours, because it includes all the zero crossings in the input image.

[BW,thresh] = edge(I,'zerocross',...) returns the threshold value.

Canny Method

    Note:   Not supported on a GPU.

BW = edge(I,'canny') specifies the Canny method.

BW = edge(I,'canny',thresh) specifies sensitivity thresholds for the Canny method. thresh is a two-element vector in which the first element is the low threshold, and the second element is the high threshold. If you specify a scalar for thresh, this scalar value is used for the high threshold and 0.4*thresh is used for the low threshold. If you do not specify thresh, or if thresh is empty ([]), edge chooses low and high values automatically. The value for thresh is relative to the highest value of the gradient magnitude of the image.

BW = edge(I,'canny',thresh,sigma) specifies the Canny method, using sigma as the standard deviation of the Gaussian filter. The default sigma is sqrt(2); the size of the filter is chosen automatically, based on sigma.

[BW,thresh] = edge(I,'canny',...) returns the threshold values as a two-element vector.

Code Generation

edge supports the generation of efficient, production-quality C/C++ code from MATLAB. When generating code, the method, direction, and sigma arguments must be a compile-time constants. In addition, nonprogrammatic syntaxes are not supported. For example, the syntax edge(im), where edge does not return a value but displays an image instead, is not supported. Generated code for this function uses a precompiled platform-specific shared library. To see a complete list of toolbox functions that support code generation, see List of Supported Functions with Usage Notes.

Class Support

I is a nonsparse 2-D numeric array. BW is a 2-D array of class logical.

gpuarrayI is a nonsparse 2-D numeric gpuArray. gpuarrayBW is a 2-D logical gpuArray.

Examples

Find the edges of an image using the Prewitt and Canny methods.

I = imread('circuit.tif');
BW1 = edge(I,'prewitt');
BW2 = edge(I,'canny');
imshow(BW1);

Prewitt Method

figure, imshow(BW2)

Canny Method

Find the edges using the Prewitt method, performing the operation on a GPU.

I = gpuArray(imread('circuit.tif'));
BW = edge(I,'prewitt');

figure, imshow(BW)

More About

expand all

Tips

For the gradient-magnitude methods (Sobel, Prewitt, Roberts), thresh is used to threshold the calculated gradient magnitude. For the zero-crossing methods, including Lap, thresh is used as a threshold for the zero-crossings; in other words, a large jump across zero is an edge, while a small jump isn't.

The Canny method applies two thresholds to the gradient: a high threshold for low edge sensitivity and a low threshold for high edge sensitivity. edge starts with the low sensitivity result and then grows it to include connected edge pixels from the high sensitivity result. This helps fill in gaps in the detected edges.

In all cases, the default threshold is chosen heuristically in a way that depends on the input data. The best way to vary the threshold is to run edge once, capturing the calculated threshold as the second output argument. Then, starting from the value calculated by edge, adjust the threshold higher (fewer edge pixels) or lower (more edge pixels).

The function edge changed in Version 7.2 (R2011a). Previous versions of the Image Processing Toolbox™ used a different algorithm for computing the Canny method. If you need the same results produced by the previous implementation, use the following syntax:

BW = edge(I,'canny_old',...)

The syntax BW = edge(... ,K) has been removed. Use the BW = edge(... ,direction) syntax instead.

The syntax edge(I,'marr-hildreth',...) has been removed. Use the edge(I,'log',...) syntax instead.

References

[1] Canny, John, "A Computational Approach to Edge Detection," IEEE Transactions on Pattern Analysis and Machine Intelligence,Vol. PAMI-8, No. 6, 1986, pp. 679-698.

[2] Lim, Jae S., Two-Dimensional Signal and Image Processing, Englewood Cliffs, NJ, Prentice Hall, 1990, pp. 478-488.

[3] Parker, James R., Algorithms for Image Processing and Computer Vision, New York, John Wiley & Sons, Inc., 1997, pp. 23-29.

See Also

| | |

Was this topic helpful?