FUNCTION REFERENCE

edge

Find edges in a grayscale image.

Find edges in a grayscale image.

Syntax

BW = edge(I)

Syntax

BW = edge(I, method)

Syntax

BW = edge(I, method, threshold)

Syntax

BW = edge(I, method, threshold, direction)

Syntax

BW = edge(I, 'canny', threshold, sigma)

Syntax

[BW, threshOut] = edge(...)

Returns a logical image with true at edge pixels. I is scaled to [0, 1] by its class range first. 'sobel' (default), 'prewitt' and 'roberts' take the gradient with the Sobel (divided by 8), Prewitt (divided by 6) or Roberts (divided by 2) kernels, replicating the border, and mark pixels whose gradient magnitude exceeds threshold and is a local maximum across the edge along the dominant gradient axis (one pixel wide; the left or top pixel of a two-pixel ridge). The default threshold is sqrt(4 * mean(gradient magnitude squared)). direction 'horizontal' or 'vertical' keeps only horizontal or vertical edges ('both' is the default); 'nothinning' marks every pixel above the threshold. 'canny' smooths with a Gaussian of sigma (default sqrt(2)), keeps local maxima of the normalised gradient magnitude along the gradient direction, and joins weak edges (above low) to strong ones (above high) through 8-connected paths; threshold is [low high] or a high value with low = 0.4 * high, by default the high value leaves 70 % of the pixels below it. threshOut is the threshold used ([low high] for Canny).

Example

A = zeros(20); A(:, 11:20) = 1; find(any(edge(A), 1))   % 10

Example

[BW, t] = edge(magic(8) / 64, 'canny'); t(1) / t(2)   % 0.4

Example

BW = edge(uint8(magic(6) * 7), 'prewitt', [], 'vertical');

Differences from MATLAB: the 'log', 'zerocross' and 'approxcanny' methods are not supported yet; thresholds are chosen by the rules above, so edge maps can differ from MATLAB's in single pixels.

Classifier overload: Syntax: e = edge(mdl,X,Y)

Returns the mean of classification score margins, weighted by the model class priors.

Example

m=fitcknn([0;2],[1;2]); edge(m,[0;2],[1;2])

Differences from MATLAB: Custom observation weights and learner subsets are unsupported.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.