0% found this document useful (0 votes)
15 views

Edge

The document describes the edge function in MATLAB, which detects edges in an intensity image. It defines the syntax and input/output arguments of the function, describes the different edge detection methods, and provides examples of edge detection using Canny and Prewitt methods as well as performing edge detection on a GPU.

Uploaded by

Murphy's Law
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Edge

The document describes the edge function in MATLAB, which detects edges in an intensity image. It defines the syntax and input/output arguments of the function, describes the different edge detection methods, and provides examples of edge detection using Canny and Prewitt methods as well as performing edge detection on a GPU.

Uploaded by

Murphy's Law
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

edge

Find edges in intensity image

Syntax
BW = edge(I)
BW = edge(I,method)
BW = edge(I,method,threshold)
BW = edge(I,method,threshold,direction)
BW = edge(___,'nothinning')
BW = edge(I,method,threshold,sigma)
BW = edge(I,method,threshold,h)
[BW,threshOut] = edge(___)
[BW,threshOut,Gv,Gh] = edge(___)
[gpuarrayBW,threshOut] = edge(gpuarrayI,___)

Description
BW = edge(I) returns a binary image BW containing 1s where the function finds edges in the input
image I and 0s elsewhere. By default, edge uses the Sobel edge detection method.
exa
BW = edge(I,method) detects edges in image I using the edge-detection algorithm specified by method.
BW = edge(I,method,threshold) returns all edges that are stronger than threshold.
BW = edge(I,method,threshold,direction) specifies the orientation of edges to detect. The Sobel and
Prewitt methods can detect edges in the vertical direction, horizontal direction, or both. The Roberts method
can detect edges at angles of 45° from horizontal, 135° from horizontal, or both. This syntax is valid only
when method is 'Sobel', 'Prewitt', or 'Roberts'.
BW = edge(___,'nothinning') skips the edge-thinning stage, which can improve performance. This syntax
is valid only when method is 'Sobel', 'Prewitt', or 'Roberts'.
BW = edge(I,method,threshold,sigma) specifies sigma, the standard deviation of the filter. This syntax is
valid only when method is 'log' or 'Canny'.
BW = edge(I,method,threshold,h) detects edges using the 'zerocross' method with a filter, h, that you
specify. This syntax is valid only when method is 'zerocross'.
[BW,threshOut] = edge(___) also returns the threshold value.
[BW,threshOut,Gv,Gh] = edge(___) also returns the directional gradient magnitudes. For the Sobel and
Prewitt methods, Gv and Gh correspond to the vertical and horizontal gradients. For the Roberts
methods, Gv and Gh correspond to the gradient at angles of 45° and 135° from horizontal, respectively. This
syntax is valid only when method is 'Sobel','Prewitt', or 'Roberts'.
exa
[gpuarrayBW,threshOut] = edge(gpuarrayI,___) performs the edge detection operation on a GPU.
The 'Canny' and 'approxcanny' methods are not supported on a GPU. The input image and the output
image are gpuArrays. This syntax requires Parallel Computing Toolbox™.
Examples
Compare Edge Detection Using Canny and Prewitt Methods
Try This Example
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')
Find Edges Using Prewitt Method on a GPU
Read a grayscale image, creating a gpuArray.
I = gpuArray(imread('circuit.tif'));
Find edges using the Prewitt method.
BW = edge(I,'prewitt');
Display the results.
figure, imshow(BW)

Input Arguments
I — Grayscale or binary image
2-D, real, nonsparse, numeric or logical array
Grayscale or binary image, specified as a 2-D, real, nonsparse, numeric or logical array.
For the 'approxcanny' method, images of datatype single or double must be normalized in the range [0
1].
Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
method — Edge detection method
'Sobel' (default) | 'Prewitt' | 'Roberts' | 'log' | 'zerocross' | 'Canny' | 'approxcanny'
Edge detection method, specified as one of the following.

Method Description
'Sobel' Finds edges at those points where the gradient of the image I is maximum, using the Sobel approximation to the derivative.
'Prewitt' Finds edges at those points where the gradient of I is maximum, using the Prewitt approximation to the derivative.
'Roberts' Finds edges at those points where the gradient of I is maximum, using the Roberts approximation to the derivative.
'log' Finds edges by looking for zero-crossings after filtering I with a Laplacian of Gaussian (LoG) filter.
Method Description
'zerocross' Finds edges by looking for zero-crossings after filtering I with a filter that you specify, h
'Canny' Finds edges by looking for local maxima of the gradient of I. The edge function calculates the gradient using the derivativ
weak edges, including weak edges in the output if they are connected to strong edges. By using two thresholds, the Canny m
likely to detect true weak edges.
'approxcanny' Finds edges using an approximate version of the Canny edge detection algorithm that provides faster execution time at the e
point images are expected to be normalized in the range [0 1].

threshold — Sensitivity threshold


numeric scalar | 2-element vector | []
Sensitivity threshold, specified as a numeric scalar for any method, or a 2-element vector for
the 'Canny' and 'approxcanny' methods. edge ignores all edges that are not stronger than threshold.
If you do not specify threshold, or if you specify an empty array ([]), then edge chooses the value or values
automatically.
 For the 'log' and 'zerocross' methods, if you specify the threshold value 0, then the output image has
closed contours because it includes all the zero-crossings in the input image.
 The 'Canny' and 'approxcanny' methods use two thresholds. edge disregards all edges with edge strength
below the lower threshold, and preserves all edges with edge strength above the higher threshold. You can
specify threshold as a 2-element vector of the form [low high] with low and high values in the range [0
1]. You can also specify threshold as a numeric scalar, which edge assigns to the higher threshold. In this
case, edge uses threshold*0.4 as the lower threshold.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
direction — Direction of edges to detect
'both' (default) | 'horizontal' | 'vertical'
Direction of edges to detect, specified as 'horizontal', 'vertical', or 'both'. The direction argument
is only valid when the method is 'Sobel', 'Prewitt', or 'Roberts'.

Note
If you select the Roberts method, then the 'horizontal' direction actually detects edges at an angle of 135°
from horizontal, and the 'vertical' direction detects edges at an angle of 45° from horizontal.
Data Types: char | string
h — Filter
matrix
Filter, specified as a matrix. The h argument is supported by the 'zerocross' method only.
Data Types: double
sigma — Standard deviation of the filter
scalar
Standard deviation of the filter, specified as a scalar. The sigma argument is supported by
the 'Canny' and 'log' methods only.

Method Description

'Canny' Scalar value that specifies the standard deviation of the Gaussian filter. The default is sqrt(2). edge cho

'log' (Laplacian of Gaussian) Scalar value that specifies the standard deviation of the Laplacian of Gaussian filter. The default is 2. The s
Data Types: double
gpuarrayI — Input image
gpuArray
Input image, specified as a gpuArray.

Output Arguments
BW — Output binary image
logical array
Output binary image, returned as a logical array of the same size as I, with 1s where the function finds edges
in I and 0s elsewhere.
threshOut — Threshold value used in the computation
numeric scalar | 2-element vector | []
Threshold value used in the computation, returned as a 2-element vector for the 'Canny' method, an empty
vector ([]) for the 'approxcanny' method, or a numeric scalar for all other edge detection methods.
Gv — Vertical gradient
numeric array
Vertical gradient, returned as a numeric array of the same size as I.

Note
If you select the Roberts method, then edge returns the gradient calculated at an angle of 45° from horizontal.

Gh — Horizontal gradient
numeric array
Horizontal gradient, returned as a numeric array of the same size as I.

Note
If you select the Roberts method, then edge returns the gradient calculated at an angle of 135° from
horizontal.
gpuarrayBW — Output binary image when run on a GPU
gpuArray
Output binary image when run on a GPU, returned as a gpuArray.

Algorithms
 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 to detect fewer edge pixels, or
lower to detect more edge pixels.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy