{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / feature / _canny / canny

function

skimage.feature._canny:canny

source: /dev/scikit-image/src/skimage/feature/_canny.py :12

Signature

def   canny ( image sigma = 1.0 low_threshold = None high_threshold = None mask = None use_quantiles = False * mode = constant cval = 0.0 )

Summary

Edge filter an image using the Canny algorithm.

Parameters

image : ndarray of shape (M, N)

Grayscale input image to detect edges on; can be of any dtype.

sigma : float, optional

Standard deviation of the Gaussian filter.

low_threshold : float, optional

Lower bound for hysteresis thresholding (linking edges). If None, low_threshold is set to 10% of dtype's max.

high_threshold : float, optional

Upper bound for hysteresis thresholding (linking edges). If None, high_threshold is set to 20% of dtype's max.

mask : ndarray of dtype bool, optional

Mask to limit the application of Canny to a certain area.

use_quantiles : bool, optional

If True then treat low_threshold and high_threshold as quantiles of the edge magnitude image, rather than absolute edge magnitude values. If True then the thresholds must be in the range [0, 1].

mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional

The mode parameter determines how the array borders are handled during Gaussian filtering, where cval is the value when mode is equal to 'constant'.

cval : float, optional

Value to fill past edges of input if mode is 'constant'.

Returns

output : ndarray of shape (M, N)

The binary edge map.

Notes

The steps of the algorithm are as follows:

  • Smooth the image using a Gaussian with sigma width.

  • Apply the horizontal and vertical Sobel operators to get the gradients within the image. The edge strength is the norm of the gradient.

  • Thin potential edges to 1-pixel wide curves. First, find the normal to the edge at each point. This is done by looking at the signs and the relative magnitude of the X-Sobel and Y-Sobel to sort the points into 4 categories: horizontal, vertical, diagonal and antidiagonal. Then look in the normal and reverse directions to see if the values in either of those directions are greater than the point in question. Use interpolation to get a mix of points instead of picking the one that's the closest to the normal.

  • Perform a hysteresis thresholding: first label all points above the high threshold as edges. Then recursively label any point above the low threshold that is 8-connected to a labeled point as an edge.

Examples

import numpy as np
import skimage as ski
rng = np.random.default_rng()
im = np.zeros((256, 256))
im[64:-64, 64:-64] = 1
im += 0.2 * rng.random(im.shape)
edges1 = ski.feature.canny(im)
edges2 = ski.feature.canny(im, sigma=3)

See also

skimage.filters.sobel

Aliases

  • skimage.feature.canny

Referenced by