Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

edge

Find edges in intensity image

Syntax

  • BW = edge(I)
  • BW = edge(I,'Sobel')
  • BW = edge(I,'Sobel',threshold)
  • BW = edge(I,'Sobel',threshold,direction)
  • BW = edge(I,'Sobel',threshold,direction,'nothinning')
  • [BW,threshOut] = edge(I,'Sobel',___)
  • BW = edge(I,'Prewitt')
  • BW = edge(I,'Prewitt',threshold)
  • BW = edge(I,'Prewitt',threshold,direction)
  • BW = edge(I,'Prewitt',threshold,direction,'nothinning')
  • [BW,threshOut] = edge(I,'Prewitt',___)
  • BW = edge(I,'Roberts')
  • BW = edge(I,'Roberts',threshold)
  • BW = edge(I,'Roberts',threshold,'nothinning')
  • [BW,threshOut] = edge(I,'Roberts',threshold,'nothinning')
  • BW = edge(I,'log')
  • BW = edge(I,'log',threshold)
  • BW = edge(I,'log',threshold,sigma)
  • [BW,threshOut] = edge(I,'log',___)
  • BW = edge(I,'zerocross',threshold,h)
  • [BW,threshOut] = edge(I,'zerocross',___)
  • BW = edge(I,'Canny')
  • BW = edge(I,'Canny',threshold)
  • BW = edge(I,'Canny',threshold,sigma)
  • [BW,threshOut] = edge(I,'Canny',___)
  • BW = edge(I,'approxcanny')
  • BW = edge(I,'approxcanny',threshold)
  • [gpuarrayBW,threshOut] = edge(gpuarrayI,___)
    example

Description

BW = edge(I) returns a binary image BW containing 1s where the function finds edges in the input image I and 0s elsewhere. The input image I is an intensity or a binary image. BW is the same size as I.

By default, edge uses the Sobel edge detection method, but you can specify any of these other methods: Canny (or a Canny approximation), Laplacian of Gaussian (log), Prewitt, Roberts, or Zero-crossings. The parameters you specify vary depending on the method you choose. The following section detail the parameters supported by each method.

BW = edge(I,'Sobel') detect edges using the Sobel method. This method finds edges using the Sobel approximation to the derivative. It returns edges at those points where the gradient of I is maximum.

BW = edge(I,'Sobel',threshold) return all edges that are stronger than threshold. If you do not specify threshold, or is you specify empty brackets ([]), edge chooses the value automatically.

BW = edge(I,'Sobel',threshold,direction) specify the direction in which the function looks for edges in the image: 'horizontal', 'vertical', or 'both'.

BW = edge(I,'Sobel',threshold,direction,'nothinning') specify whether to skip the additional edge-thinning stage, 'nothinning'. Skipping this stage can improve performance. The default value is 'thinning'.

[BW,threshOut] = edge(I,'Sobel',___) returns the threshold value.

BW = edge(I,'Prewitt') detect edges using the Prewitt method. This method finds edges using the Prewitt approximation to the derivative. It returns edges at those points where the gradient of I is maximum.

BW = edge(I,'Prewitt',threshold) return all edges that are stronger than threshold. If you do not specify threshold, or is you specify empty brackets ([]), edge chooses the value automatically.

BW = edge(I,'Prewitt',threshold,direction) specify the direction in which the function looks for edges in the image: 'horizontal', 'vertical', or 'both'.

BW = edge(I,'Prewitt',threshold,direction,'nothinning') specify whether to skip the additional edge-thinning stage, 'nothinning'. Skipping this stage can improve performance. The default value is 'thinning'.

[BW,threshOut] = edge(I,'Prewitt',___) returns the threshold value.

BW = edge(I,'Roberts') detect edges using the Roberts method. This method finds edges using the Roberts approximation to the derivative. It returns edges at those points where the gradient of I is maximum.

BW = edge(I,'Roberts',threshold) return all edges that are stronger than threshold. If you do not specify threshold, or is you specify empty brackets ([]), edge chooses the value automatically.

BW = edge(I,'Roberts',threshold,'nothinning') specify whether to skip the additional edge-thinning stage, 'nothinning'. Skipping this stage can improve performance. The default value is 'thinning'.

[BW,threshOut] = edge(I,'Roberts',threshold,'nothinning') returns the threshold value.

BW = edge(I,'log') detect edges using the Laplacian of Gaussian ('log') method. This method finds edges by looking for zero-crossings after filtering I with a Laplacian of Gaussian filter.

BW = edge(I,'log',threshold) return all edges that are stronger than threshold. If you do not specify threshold, or is you specify empty brackets ([]), edge chooses the value automatically.

BW = edge(I,'log',threshold,sigma) specify sigma, 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,threshOut] = edge(I,'log',___) returns the threshold value.

BW = edge(I,'zerocross',threshold,h) detect edges using the 'zerocross' method. This method finds edges by looking for zero-crossings after filtering I with a filter that you specify, h. The edge function returns edges that are stronger than threshold. If you do not specify threshold, or is you specify empty brackets ([]), edge chooses the threshold value automatically.

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

BW = edge(I,'Canny') detect edges using the Canny method. The Canny method finds edges by looking for local maxima of the gradient of I. The edge function calculates the gradient using the derivative of a Gaussian filter. This method uses two thresholds to detect strong and weak edges, including weak edges in the output if they are connected to strong edges. By using two thresholds, the Canny method is less likely than the other methods to be fooled by noise, and more likely to detect true weak edges.

The Canny method is not supported on a GPU.

BW = edge(I,'Canny',threshold) return all edges that are stronger than threshold. If you do not specify threshold, or if you specify empty brackets ([]), edge chooses the value automatically. threshold 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, edge uses this value for the high value and uses threshold*0.4 for the low threshold.

BW = edge(I,'Canny',threshold,sigma) specify sigma, the standard deviation of the Gaussian filter. The default sigma is sqrt(2). edge chooses the size of the filter automatically, based on sigma.

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

BW = edge(I,'approxcanny') detect edges using the approximate Canny method. The 'approxcanny' method is an approximate version of the Canny edge detection algorithm that provides faster execution time at the expense of less precise detection. For the approxcanny method, floating point images are expected to be normalized in the range [0 1].

BW = edge(I,'approxcanny',threshold) specifies sensitivity thresholds for the 'approxcanny' method. threshold is a two element vector, the first element of which specifies the lower threshold for edge strength, below which all edges are disregarded. The second element specifies the higher threshold, above which all edge pixels are preserved. The range of values allowed is between [0 1]. If you specify a scalar, edge uses this value for the high value and uses threshold*0.4 for the low threshold. If you do not specify threshold, or if threshold is empty ([]), edge chooses low and high values automatically.

example

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

Code Generation support: Yes.

MATLAB Function Block support: Yes.

Examples

collapse all

Read a grayscale image into the workspace and display it.

I = imread('circuit.tif');
imshow(I)

Find edges using the Canny method.

BW1 = edge(I,'Canny');

Find edges using the Prewitt method.

BW2 = edge(I,'Prewitt');

Display both results side-by-side.

imshowpair(BW1,BW2,'montage')

Read grayscale image, creating a gpuArray.

I = gpuArray(imread('circuit.tif'));

Find edges using the Prewitt method.

BW = edge(I,'prewitt');

Display results.

figure, imshow(BW)

Input Arguments

collapse all

Input intensity or binary image, specified as a 2-D, real, nonsparse, numeric, or logical array.

For the 'approxcanny' method, edge expects floating-point images to be normalized in the range [0 1].

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Sensitivity threshold, specified as a numeric scalar or, for the Canny and approxcanny methods only, a two-element vector. edge ignores all edges that are not stronger than threshold. If you do not specify threshold, or if you specify an empty array ([]), edge chooses the value automatically. For more information about this parameter, see Tips.

For the 'log' (Laplacian of Gaussian) and 'zerocross' methods, if you specify the threshold value 0, the output image has closed contours because it includes all the zero-crossings in the input image.

For the 'Canny' and 'zerocross' methods, if you specify the threshold value 0, the output image has closed contours because it includes all the zero-crossings in the input image.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Direction of edges to detect, specified as 'horizontal', 'vertical', or 'both'. This is only used with the Sobel and Prewitt methods.

Data Types: char

Filter, specified as a matrix.

Data Types: double

Standard deviation of the filter, specified as a scalar. Supported by the Canny and log methods only.

MethodDescription
'Canny'

Scalar value that specifies the standard deviation of the Gaussian filter. The default is sqrt(2). edge chooses the size of the filter automatically, based on sigma.

'log' (Laplacian of Gaussian)

Scalar value that specifies the standard deviation of the Laplacian of Gaussian filter. The default is 2. The size of the filter is n-by-n, where n=ceil(sigma*3)*2+1.

Data Types: double

Input image, specified as a gpuArray.

Output Arguments

collapse all

Output binary image, returned as a logical array, the same size as I, with 1s where the function finds edges in I and 0s elsewhere.

Threshold value used in the computation, returned as a numeric scalar.

Output binary image when run on a GPU, returned as a gpuArray.

More About

collapse all

Code Generation

This function supports the generation of C code using MATLAB® Coder™. Note that if you choose the generic MATLAB Host Computer target platform, the function generates code that uses a precompiled, platform-specific shared library. Use of a shared library preserves performance optimizations but limits the target platforms for which code can be generated. For more information, see Understanding Code Generation with Image Processing Toolbox.

When generating code, note the following:

  • The method, direction, and sigma arguments must be compile-time constants.

  • Nonprogrammatic syntaxes are not supported. For example, if you do not specify a return value,edge displays an image. This syntax is not supported.

MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.

The thresh and sigma arguments must be compile-time constants.

Tips

  • Notes about the threshold parameter:

    • For the gradient-magnitude edge detection methods (Sobel, Prewitt, Roberts), edge uses threshold to threshold the calculated gradient magnitude. For the zero-crossing methods, including Laplacian of Gaussian, edge uses threshold as a threshold for the zero-crossings. In other words, a large jump across zero is an edge, while a small jump is not.

    • 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, edge chooses the default threshold heuristically, depending 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.

Introduced before R2006a

Was this topic helpful?