skimage2.feature#
Warning
This module is part of the experimental skimage2 namespace and is subject to change without notice.
Do not use it in production code.
See the migration guide for more details.
Feature detection and extraction, for example, texture analysis, corners, etc.
Edge filter an image using the Canny algorithm. |
|
Find peaks in an image as coordinate list. |
- skimage2.feature.canny(image, *, sigma=1.0, low_threshold=None, high_threshold=None, mask=None, use_quantiles=False, mode='nearest', cval=0.0)[source]#
Edge filter an image using the Canny algorithm.
- Parameters:
- imagendarray of shape (M, N)
Grayscale input image to detect edges on; can be of any dtype.
- sigmafloat, optional
Standard deviation of the Gaussian filter.
- low_thresholdfloat, optional
Lower bound for hysteresis thresholding (linking edges). If None, low_threshold is set to 10% of dtype’s max.
- high_thresholdfloat, optional
Upper bound for hysteresis thresholding (linking edges). If None, high_threshold is set to 20% of dtype’s max.
- maskndarray of dtype bool, optional
Mask to limit the application of Canny to a certain area.
- use_quantilesbool, optional
If
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’}, optional
The
modeparameter determines how the array borders are handled during Gaussian filtering, wherecvalis the value when mode is equal to ‘constant’.- cvalfloat, optional
Value to fill past edges of input
imageifmodeis ‘constant’.
- Returns:
- outputndarray of shape (M, N)
The binary edge map.
See also
skimage2.filters.sobel
Notes
The steps of the algorithm are as follows:
Smooth the image using a Gaussian with width
sigma.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.
References
[1]Canny, J., A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986 DOI:10.1109/TPAMI.1986.4767851
[2]William Green’s Canny tutorial https://web.archive.org/web/20110224083140/http://www.pages.drexel.edu/~weg22/can_tut.html
Examples
>>> import _skimage2 as ski2 >>> import numpy as np >>> rng = np.random.default_rng() >>> # Generate noisy image of a square >>> im = np.zeros((256, 256)) >>> im[64:-64, 64:-64] = 1 >>> im += 0.2 * rng.random(im.shape) >>> # First trial with the Canny filter, with the default smoothing >>> edges1 = ski2.feature.canny(im) >>> # Increase the smoothing for better results >>> edges2 = ski2.feature.canny(im, sigma=3)
- skimage2.feature.peak_local_max(image, *, min_distance=1, threshold_abs=None, threshold_rel=None, exclude_border=1, num_peaks=None, footprint=None, labels=None, num_peaks_per_label=None, p_norm=2.0)[source]#
Find peaks in an image as coordinate list.
Peaks are the local maxima in a region of
floor(2 * min_distance + 1)(i.e. peaks are separated by at leastmin_distance).If both
threshold_absandthreshold_relare provided, the maximum of the two is chosen as the minimum intensity threshold of peaks.- Parameters:
- imagendarray
Input image.
- min_distancefloat, optional
The minimal allowed distance separating peaks. To find the maximum number of peaks, use
min_distance=1. See alsop_norm.- threshold_absfloat, optional
Minimum intensity of peaks. By default, the absolute threshold is the minimum intensity of the image.
- threshold_relfloat, optional
Minimum intensity of peaks, calculated as
max(image) * threshold_rel.- exclude_borderint or tuple of (int, …), optional
Control peak detection close to the border of
image. By default, only peaks exactly on the border are excluded.0Distance to border has no effect, all peaks are identified.
- positive integer
Exclude peaks that are within this distance of the border.
- tuple of positive integers
Same as for a single integer but with different distances for each respective dimension.
The value of
p_normhas no impact on this border distance.- num_peaksint, optional
If given, maximum number of allowed peaks. When the number of peaks exceeds
num_peaks, returnnum_peakspeaks based on highest peak intensity.- footprintndarray of dtype bool, optional
Binary mask that determines the neighborhood (where
True) in which a peak must be a local maximum (see Notes). If not given, defaults to an array of ones of sizefloor(2 * min_distance + 1).- labelsndarray of dtype int, optional
If provided, each unique region
labels == valuerepresents a unique region to search for peaks. Zero labels are reserved for background.- num_peaks_per_labelint, optional
If given, maximum number of peaks for each label.
- p_normfloat, optional
Which Minkowski p-norm to use. Should be in the range [1, inf]. A finite large p may cause a ValueError if overflow can occur.
infcorresponds to the Chebyshev distance and 2 to the Euclidean distance. See alsonumpy.linalg.norm().
- Returns:
- outputndarray of shape (N, D)
The coordinates of the peaks.
Ndenotes the number of peaks andDcorresponds to the number of dimensions inimage.
See also
skimage2.feature.corner_peaks
Notes
The peak local maximum function returns the coordinates of local peaks (maxima) in an image. Internally, a maximum filter is used for finding local maxima. This operation dilates the original image. After comparison of the dilated and original images, this function returns the coordinates of the peaks where the dilated image equals the original image.
Examples
>>> import _skimage2 as ski2 >>> image = np.array( ... [[1, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 1, 0, 0], ... [0, 0, 3, 0, 2, 0, 0], ... [0, 0, 2, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0]] ... )
Find all peaks
>>> ski2.feature.peak_local_max(image) array([[3, 2], [3, 4]])
Ensure peaks are at least 2 pixels apart
>>> ski2.feature.peak_local_max(image, min_distance=2) array([[3, 2]])
Allow peaks on the image border
>>> ski2.feature.peak_local_max(image, exclude_border=0) array([[3, 2], [3, 4], [0, 0]])