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, optionalStandard deviation of the Gaussian filter.
low_threshold: float, optionalLower bound for hysteresis thresholding (linking edges). If None, low_threshold is set to 10% of dtype's max.
high_threshold: float, optionalUpper bound for hysteresis thresholding (linking edges). If None, high_threshold is set to 20% of dtype's max.
mask: ndarray of dtype bool, optionalMask to limit the application of Canny to a certain area.
use_quantiles: bool, optionalIf
Truethen treat low_threshold and high_threshold as quantiles of the edge magnitude image, rather than absolute edge magnitude values. IfTruethen the thresholds must be in the range [0, 1].mode: {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optionalThe
modeparameter determines how the array borders are handled during Gaussian filtering, wherecvalis the value whenmodeis equal to 'constant'.cval: float, optionalValue to fill past edges of input if
modeis '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
sigmawidth.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
Aliases
-
skimage.feature.canny