Documentation Center

  • Trial Software
  • Product Updates

Edge Detection

Find edges of objects in images using Sobel, Prewitt, Roberts, or Canny method

Library

Analysis & Enhancement

visionanalysis

Description

If, for the Method parameter, you select Sobel, Prewitt, or Roberts, the Edge Detection block finds the edges in an input image by approximating the gradient magnitude of the image. The block convolves the input matrix with the Sobel, Prewitt, or Roberts kernel. The block outputs two gradient components of the image, which are the result of this convolution operation. Alternatively, the block can perform a thresholding operation on the gradient magnitudes and output a binary image, which is a matrix of Boolean values. If a pixel value is 1, it is an edge.

If, for the Method parameter, you select Canny, the Edge Detection block finds edges by looking for the local maxima of the gradient of the input image. It calculates the gradient using the derivative of the Gaussian filter. The Canny method uses two thresholds to detect strong and weak edges. It includes the weak edges in the output only if they are connected to strong edges. As a result, the method is more robust to noise, and more likely to detect true weak edges.

PortInput/OutputSupported Data TypesComplex Values Supported

I

Matrix of intensity values

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point (not supported for the Canny method)

  • 8-, 16-, 32-bit signed integer (not supported for the Canny method)

  • 8-, 16-, 32-bit unsigned integer (not supported for the Canny method)

No

Th

Matrix of intensity values

Same as I port

No

Edge

Matrix that represents a binary image

Boolean

No

Gv

Matrix of gradient values in the vertical direction

Same as I port

No

Gh

Matrix of gradient values in the horizontal direction

Same as I port

No

G45

Matrix of gradient values

Same as I port

No

G135

Matrix of gradient values

Same as I port

No

The output of the Gv, Gh, G45, and G135 ports is the same data type as the input to the I port. The input to the Th port must be the same data type as the input to the I port.

Use the Method parameter to specify which algorithm to use to find edges. You can select Sobel, Prewitt, Roberts, or Canny to find edges using the Sobel, Prewitt, Roberts, or Canny method.

Sobel, Prewitt, and Roberts Methods

Use the Output type parameter to select the format of the output. If you select Binary image, the block outputs a Boolean matrix at the Edge port. The nonzero elements of this matrix correspond to the edge pixels and the zero elements correspond to the background pixels. If you select Gradient components and, for the Method parameter, you select Sobel or Prewitt, the block outputs the gradient components that correspond to the horizontal and vertical edge responses at the Gh and Gv ports, respectively. If you select Gradient components and, for the Method parameter, you select Roberts, the block outputs the gradient components that correspond to the 45 and 135 degree edge responses at the G45 and G135 ports, respectively. If you select Binary image and gradient components, the block outputs both the binary image and the gradient components of the image.

Select the User-defined threshold check box to define a threshold values or values. If you clear this check box, the block computes the threshold for you.

Use the Threshold source parameter to specify how to enter your threshold value. If you select Specify via dialog, the Threshold parameter appears in the dialog box. Enter a threshold value that is within the range of your input data. If you choose Input port, use input port Th to specify a threshold value. This value must have the same data type as the input data. Gradient magnitudes above the threshold value correspond to edges.

The Edge Detection block computes the automatic threshold using the mean of the gradient magnitude squared image. However, you can adjust this threshold using the Threshold scale factor (used to automatically calculate threshold value) parameter. The block multiplies the value you enter with the automatic threshold value to determine a new threshold value.

Select the Edge thinning check box to reduce the thickness of the edges in your output image. This option requires additional processing time and memory resources.

    Note   This block is most efficient in terms of memory usage and processing time when you clear the Edge thinning check box and use the Threshold parameter to specify a threshold value.

Canny Method

Select the User-defined threshold check box to define the low and high threshold values. If you clear this check box, the block computes the threshold values for you.

Use the Threshold source parameter to specify how to enter your threshold values. If you select Specify via dialog, the Threshold [low high] parameter appears in the dialog box. Enter the threshold values. If a pixel's magnitude in the gradient image, which is formed by convolving the input image with the derivative of the Gaussian filter, exceeds the high threshold, then the pixel corresponds to a strong edge. Any pixel connected to a strong edge and having a magnitude greater than the low threshold corresponds to a weak edge. If, for the Threshold source parameter, you choose Input port, use input port Th to specify a two-element vector of threshold values. These values must have the same data type as the input data.

The Edge Detection block computes the automatic threshold values using an approximation of the number of weak and nonedge image pixels. Enter this approximation for the Approximate percentage of weak edge and nonedge pixels (used to automatically calculate threshold values) parameter.

Use the Standard deviation of Gaussian filter parameter to define the Gaussian filter whose derivative is convolved with the input image.

Fixed-Point Data Types

The following diagram shows the data types used in the Edge Detection block for fixed-point signals.

The block squares the threshold and compares it to the sum of the squared gradients to avoid using square roots.

You can set the product output and accumulator data types in the block mask as discussed in the next section.

Dialog Box

The Main pane of the Edge Detection dialog box appears as shown in the following figure.

Method

Select the method by which to perform edge detection. Your choices are Sobel, Prewitt, Roberts, or Canny.

Output type

Select the desired form of the output. If you select Binary image, the block outputs a matrix that is filled with ones, which correspond to edges, and zeros, which correspond to the background. If you select Gradient components and, for the Method parameter, you select Sobel or Prewitt, the block outputs the gradient components that correspond to the horizontal and vertical edge responses. If you select Gradient components and, for the Method parameter, you select Roberts, the block outputs the gradient components that correspond to the 45 and 135 degree edge responses. If you select Binary image and gradient components, the block outputs both the binary image and the gradient components of the image. This parameter is visible if, for the Method parameter, you select Sobel, Prewitt, or Roberts.

User-defined threshold

If you select this check box, you can enter a desired threshold value. If you clear this check box, the block computes the threshold for you. This parameter is visible if, for the Method parameter, you select Sobel, Prewitt, or Roberts, and, for the Output type parameter, you select Binary image or Binary image and gradient components. This parameter is also visible if, for the Method parameter, you select Canny.

Threshold source

If you select Specify via dialog, enter your threshold value in the dialog box. If you choose Input port, use the Th input port to specify a threshold value that is the same data type as the input data. This parameter is visible if you select the User-defined threshold check box.

Threshold

Enter a threshold value that is within the range of your input data. This parameter is visible if, for the Method parameter, you select Sobel, Prewitt, or Roberts, you select the User-defined threshold check box, and, for Threshold source parameter, you select Specify via dialog. .

Threshold [low high]

Enter the low and high threshold values that define the weak and strong edges. This parameter is visible if, for the Method parameter, you select Canny. Then you select the User-defined threshold check box, and, for Threshold source parameter, you select Specify via dialog. Tunable.

Threshold scale factor (used to automatically calculate threshold value)

Enter a multiplier that is used to adjust the calculation of the automatic threshold. This parameter is visible if, for the Method parameter, you select Sobel, Prewitt, or Roberts, and you clear the User-defined threshold check box. Tunable.

Edge thinning

Select this check box if you want the block to perform edge thinning. This option requires additional processing time and memory resources. This parameter is visible if, for the Method parameter, you select Sobel, Prewitt, or Roberts, and for the Output type parameter, you select Binary image or Binary image and gradient components.

Approximate percentage of weak edge and nonedge pixels (used to automatically calculate threshold values)

Enter the approximate percentage of weak edge and nonedge image pixels. The block computes the automatic threshold values using this approximation. This parameter is visible if, for the Method parameter, you select Canny. Tunable.

Standard deviation of Gaussian filter

Enter the standard deviation of the Gaussian filter whose derivative is convolved with the input image. This parameter is visible if, for the Method parameter, you select Canny.

The Data Types pane of the Edge Detection dialog box appears as shown in the following figure.

Rounding mode

Select the rounding mode for fixed-point operations.

Overflow mode

Select the overflow mode for fixed-point operations.

Product output

Here, the internal coefficients are the Sobel, Prewitt, or Roberts masks. As depicted in the previous figure, the output of the multiplier is placed into the product output data type and scaling. Use this parameter to specify how to designate this product output word and fraction lengths.

  • When you select Same as first input, these characteristics match those of the first input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the product output, in bits.

  • When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the product output. The bias of all signals in the Computer Vision System Toolbox™ blocks is 0.

Accumulator

As depicted in the previous figure, inputs to the accumulator are cast to the accumulator data type. The output of the adder remains in the accumulator data type as each element of the input is added to it. Use this parameter to specify how to designate this accumulator word and fraction lengths.

  • When you select Same as product output, these characteristics match those of the product output.

  • When you select Same as first input, these characteristics match those of the first input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the accumulator, in bits.

  • When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the accumulator. The bias of all signals in the Computer Vision System Toolbox blocks is 0.

Gradients

Choose how to specify the word length and fraction length of the outputs of the Gv and Gh ports. This parameter is visible if, for the Output type parameter, you choose Gradient components or Binary image and gradient components:

  • When you select Same as accumulator, these characteristics match those of the accumulator.

  • When you select Same as product output, these characteristics match those of the product output.

  • When you select Same as first input, these characteristics match those of the first input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the output, in bits.

  • When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the output. The bias of all signals in the Computer Vision System Toolbox blocks is 0.

Lock data type settings against change by the fixed-point tools

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block mask. For more information, see fxptdlg, a reference page on the Fixed-Point Tool in the Simulink® documentation.

References

[1] Gonzales, Rafael C. and Richard E. Woods. Digital Image Processing. 2nd ed. Englewood Cliffs, NJ: Prentice-Hall, 2002.

[2] Pratt, William K. Digital Image Processing, 2nd ed. New York: John Wiley & Sons, 1991.

See Also

edge

Image Processing Toolbox™

Was this topic helpful?