Edge Detection
Find edges of objects in images using Sobel, Prewitt, Roberts, or Canny method
Libraries:
Computer Vision Toolbox /
Analysis & Enhancement
Description
The Edge Detection block finds edges of objects in an input image. The block supports four methods: Sobel, Prewitt, Roberts, and Canny. The first three methods find the edges by approximating the gradient magnitude of the image. The block convolves the input matrix with the Sobel, Prewitt, or Roberts kernel respectively, and outputs the resulting gradient components of the image. Additionally, the block outputs a binary image of the edge detections by thresholding the gradient magnitude.
The Canny method computes the gradient of input image using the derivative of the Gaussian filter. It then finds edges by looking for the local maxima of the gradient. This method uses two thresholds to detect the strong and weak edges. The weak edges are part of the output only if they are connected to strong edges. The block outputs a binary image of the edge detections for this method.
Examples
Edge Detection of Intensity Image
Detect edges in an intensity image using the Canny edge detector.
Ports
Input
Input image, specified as a matrix of intensity values.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Note
The Canny method does not support 8-bit, 16-bit, or 32-bit signed fixed-point integers or 8-bit, 16-bit, or 32-bit unsigned integers.
Specify a threshold as a scalar or a two-element vector to detect edges from the gradient. The data type of this value must match the input image data type. For the Canny edge detection method, the threshold must be a two-element vector in the range [0 1]. For the other methods, the threshold is a scalar.
Dependencies
To enable this port:
Set the Method parameter to
Canny. Alternatively, set the Method parameter toSobel,Prewitt, orRoberts, and also set the Output type parameter toBinary imageorBinary image and gradient components.Select the User-defined threshold.
Set the Threshold source parameter to
Input port.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Note
The Canny method does not support 8-bit, 16-bit, or 32-bit signed fixed-point integers or 8-bit, 16-bit, or 32-bit unsigned integers.
Output
Edge detections, returned as a binary image. The pixels with the value of
1 represent the edge pixels.
Dependencies
This port is always enabled when you set the Method
parameter to Canny. To enable this port for the
Sobel, Prewitt, or
Roberts methods, set the Output
type parameter to Binary image or
Binary image and gradient components.
Data Types: Boolean
Matrix of gradient responses to the vertical edges.
Dependencies
To enable this port, set these parameters:
Method —
SobelorPrewittOutput type —
Gradient componentsorBinary image and gradient components
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Matrix of gradient responses to the horizontal edges.
Dependencies
To enable this port, set these parameters:
Method —
SobelorPrewittOutput type —
Gradient componentsorBinary image and gradient components
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Matrix of gradient responses to edges at 45 degrees.
Dependencies
To enable this port, set these parameters:
Method —
RobertsOutput type —
Gradient componentsorBinary image and gradient components
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Matrix of gradient responses to edges at 135 degrees.
Dependencies
To enable this port, set these parameters:
Method —
RobertsOutput type —
Gradient componentsorBinary image and gradient components
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Parameters
Main
Specify a method to detect edges in the input image. You can choose from
Sobel, Prewitt,
Roberts or Canny.
Specify the type of output image from one of these options:
Binary image— The block outputs a Boolean matrix at the Edge port. The elements of the matrix labeled1represent the edge pixels.Gradient components— The block outputs the gradient components. For theSobelandPrewittmethods, the gradient components correspond to the horizontal and vertical edge responses at the Gh and Gv ports respectively. For theRobertsmethod the gradient components correspond to 45 degree and 135 degree edge responses at the G45 and G135 ports respectively.Binary image and gradient components— The block outputs both the binary image and the gradient components of the image
Dependencies
To enable this parameter, set the Method parameter to
Sobel, Prewitt, or
Roberts.
Specify a desired threshold value via dialog box or the Th port.
Dependencies
This parameter is always enabled when you set the Method
parameter to Canny. To enable this parameter for the
Sobel, Prewitt, or
Roberts methods, set the Output type
parameter to Binary image or Binary image and
gradient components.
Select the source to enter the threshold value from one of these options:
Input port— Specify a threshold value using the Th port. The data type of this value must match the input image data type.Specify via dialog— Enter the desired threshold value in the dialog box.
Dependencies
To enable this parameter:
Set the Method parameter to
Canny. Alternatively set the Method parameter toSobel,Prewitt, orRoberts, and also set the Output type parameter toBinary imageorBinary image and gradient components.Select the User-defined threshold.
Specify the threshold value that is within the range of your input data. This threshold applies to Sobel, Prewitt, and Roberts edge detection methods.
Dependencies
To enable this parameter, set these block parameters:
Method —
Sobel,Prewitt, orRobertsOutput type —
Binary imageorBinary image and gradient componentsUser-defined threshold —
On.Threshold source —
Specify via dialog
Specify the threshold for the Canny edge detection as a two-element vector in the range [0 1]. The elements of the vector specifies the low and high threshold values for the weak and strong edges respectively.
Dependencies
To enable this parameter, set these block parameters:
Method —
CannyUser-defined threshold —
On.Threshold source —
Specify via dialog
Specify the threshold scale factor to automatically calculate threshold value. The block computes the automatic threshold using the mean of the gradient magnitude squared image and multiplies the value of this parameter with the automatic threshold value to determine a new threshold value.
Dependencies
To enable this parameter, set these block parameters:
Method —
Sobel,Prewitt, orRobertsOutput type —
Binary imageorBinary image and gradient componentsUser-defined threshold —
Off
Select this parameter to reduce the thickness of the edges in your output images. This option requires additional processing time and memory resources.
Tip
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.
Dependencies
To enable this parameter, set these block parameters:
Method —
Sobel,Prewitt, orRobertsOutput type —
Binary imageorBinary image and gradient components
Specify the approximate percentage of weak edge and nonedge image pixels. The block computes the automatic threshold values using this value.
Dependencies
To enable this parameter, set these block parameters:
Method —
CannyUser-defined threshold —
Off
Specify the standard deviation of Gaussian filter used for Canny edge detection algorithm.
Dependencies
To enable this parameter, set the Method parameter to
Canny.
Data Types
For information about the fixed-point block parameters, see Specify Fixed-Point Attributes for Blocks (DSP System Toolbox).
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
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. NY: John Wiley & Sons, 1991.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
When you select the Normalized output check box, the block input cannot be fixed point.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

