Module: feature

BRIEF

class skimage.feature.BRIEF(descriptor_size=256, patch_size=49, mode='normal', sigma=1, sample_seed=1)

Bases: skimage.feature.util.DescriptorExtractor

BRIEF binary descriptor extractor.

BRIEF (Binary Robust Independent Elementary Features) is an efficient feature point descriptor. It is highly discriminative even when using relatively few bits and is computed using simple intensity difference tests.

For each keypoint, intensity comparisons are carried out for a specifically distributed number N of pixel-pairs resulting in a binary descriptor of length N. For binary descriptors the Hamming distance can be used for feature matching, which leads to lower computational cost in comparison to the L2 norm.

Parameters:

descriptor_size : int, optional

Size of BRIEF descriptor for each keypoint. Sizes 128, 256 and 512 recommended by the authors. Default is 256.

patch_size : int, optional

Length of the two dimensional square patch sampling region around the keypoints. Default is 49.

mode : {‘normal’, ‘uniform’}, optional

Probability distribution for sampling location of decision pixel-pairs around keypoints.

sample_seed : int, optional

Seed for the random sampling of the decision pixel-pairs. From a square window with length patch_size, pixel pairs are sampled using the mode parameter to build the descriptors using intensity comparison. The value of sample_seed must be the same for the images to be matched while building the descriptors.

sigma : float, optional

Standard deviation of the Gaussian low-pass filter applied to the image to alleviate noise sensitivity, which is strongly recommended to obtain discriminative and good descriptors.

Examples

>>> from skimage.feature import (corner_harris, corner_peaks, BRIEF,
...                              match_descriptors)
>>> import numpy as np
>>> square1 = np.zeros((8, 8), dtype=np.int32)
>>> square1[2:6, 2:6] = 1
>>> square1
array([[0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
>>> square2 = np.zeros((9, 9), dtype=np.int32)
>>> square2[2:7, 2:7] = 1
>>> square2
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
>>> keypoints1 = corner_peaks(corner_harris(square1), min_distance=1)
>>> keypoints2 = corner_peaks(corner_harris(square2), min_distance=1)
>>> extractor = BRIEF(patch_size=5)
>>> extractor.extract(square1, keypoints1)
>>> descriptors1 = extractor.descriptors
>>> extractor.extract(square2, keypoints2)
>>> descriptors2 = extractor.descriptors
>>> matches = match_descriptors(descriptors1, descriptors2)
>>> matches
array([[0, 0],
       [1, 1],
       [2, 2],
       [3, 3]])
>>> keypoints1[matches[:, 0]]
array([[2, 2],
       [2, 5],
       [5, 2],
       [5, 5]])
>>> keypoints2[matches[:, 1]]
array([[2, 2],
       [2, 6],
       [6, 2],
       [6, 6]])

Attributes

__init__(descriptor_size=256, patch_size=49, mode='normal', sigma=1, sample_seed=1)
extract(image, keypoints)

Extract BRIEF binary descriptors for given keypoints in image.

Parameters:

image : 2D array

Input image.

keypoints : (N, 2) array

Keypoint coordinates as (row, col).

CENSURE

class skimage.feature.CENSURE(min_scale=1, max_scale=7, mode='DoB', non_max_threshold=0.15, line_threshold=10)

Bases: skimage.feature.util.FeatureDetector

CENSURE keypoint detector.

min_scale : int, optional
Minimum scale to extract keypoints from.
max_scale : int, optional
Maximum scale to extract keypoints from. The keypoints will be extracted from all the scales except the first and the last i.e. from the scales in the range [min_scale + 1, max_scale - 1]. The filter sizes for different scales is such that the two adjacent scales comprise of an octave.
mode : {‘DoB’, ‘Octagon’, ‘STAR’}, optional
Type of bi-level filter used to get the scales of the input image. Possible values are ‘DoB’, ‘Octagon’ and ‘STAR’. The three modes represent the shape of the bi-level filters i.e. box(square), octagon and star respectively. For instance, a bi-level octagon filter consists of a smaller inner octagon and a larger outer octagon with the filter weights being uniformly negative in both the inner octagon while uniformly positive in the difference region. Use STAR and Octagon for better features and DoB for better performance.
non_max_threshold : float, optional
Threshold value used to suppress maximas and minimas with a weak magnitude response obtained after Non-Maximal Suppression.
line_threshold : float, optional
Threshold for rejecting interest points which have ratio of principal curvatures greater than this value.

References

[R89]Motilal Agrawal, Kurt Konolige and Morten Rufus Blas “CENSURE: Center Surround Extremas for Realtime Feature Detection and Matching”, http://link.springer.com/content/pdf/10.1007%2F978-3-540-88693-8_8.pdf
[R90]Adam Schmidt, Marek Kraft, Michal Fularz and Zuzanna Domagala “Comparative Assessment of Point Feature Detectors and Descriptors in the Context of Robot Navigation” http://www.jamris.org/01_2013/saveas.php?QUEST=JAMRIS_No01_2013_P_11-20.pdf

Examples

>>> from skimage.data import lena
>>> from skimage.color import rgb2gray
>>> from skimage.feature import CENSURE
>>> img = rgb2gray(lena()[100:300, 100:300])
>>> censure = CENSURE()
>>> censure.detect(img)
>>> censure.keypoints
array([[ 71, 148],
       [ 77, 186],
       [ 78, 189],
       [ 89, 174],
       [127, 134],
       [131, 133],
       [134, 125],
       [137, 125],
       [149,  36],
       [162, 165],
       [168, 167],
       [170,   5],
       [171,  29],
       [179,  20],
       [194,  65]])
>>> censure.scales
array([2, 4, 2, 3, 4, 2, 2, 3, 4, 6, 3, 2, 3, 4, 2])

Attributes

keypoints (N, 2) array Keypoint coordinates as (row, col).
scales (N, ) array Corresponding scales.
__init__(min_scale=1, max_scale=7, mode='DoB', non_max_threshold=0.15, line_threshold=10)
detect(image)

Detect CENSURE keypoints along with the corresponding scale.

Parameters:

image : 2D ndarray

Input image.

ORB

class skimage.feature.ORB(downscale=1.2, n_scales=8, n_keypoints=500, fast_n=9, fast_threshold=0.08, harris_k=0.04)

Bases: skimage.feature.util.FeatureDetector, skimage.feature.util.DescriptorExtractor

Oriented FAST and rotated BRIEF feature detector and binary descriptor extractor.

Parameters:

n_keypoints : int, optional

Number of keypoints to be returned. The function will return the best n_keypoints according to the Harris corner response if more than n_keypoints are detected. If not, then all the detected keypoints are returned.

fast_n : int, optional

The n parameter in skimage.feature.corner_fast. Minimum number of consecutive pixels out of 16 pixels on the circle that should all be either brighter or darker w.r.t test-pixel. A point c on the circle is darker w.r.t test pixel p if Ic < Ip - threshold and brighter if Ic > Ip + threshold. Also stands for the n in FAST-n corner detector.

fast_threshold : float, optional

The threshold parameter in feature.corner_fast. Threshold used to decide whether the pixels on the circle are brighter, darker or similar w.r.t. the test pixel. Decrease the threshold when more corners are desired and vice-versa.

harris_k : float, optional

The k parameter in skimage.feature.corner_harris. Sensitivity factor to separate corners from edges, typically in range [0, 0.2]. Small values of k result in detection of sharp corners.

downscale : float, optional

Downscale factor for the image pyramid. Default value 1.2 is chosen so that there are more dense scales which enable robust scale invariance for a subsequent feature description.

n_scales : int, optional

Maximum number of scales from the bottom of the image pyramid to extract the features from.

References

[R91]Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski “ORB: An efficient alternative to SIFT and SURF” http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf

Examples

>>> from skimage.feature import ORB, match_descriptors
>>> img1 = np.zeros((100, 100))
>>> img2 = np.zeros_like(img1)
>>> np.random.seed(1)
>>> square = np.random.rand(20, 20)
>>> img1[40:60, 40:60] = square
>>> img2[53:73, 53:73] = square
>>> detector_extractor1 = ORB(n_keypoints=5)
>>> detector_extractor2 = ORB(n_keypoints=5)
>>> detector_extractor1.detect_and_extract(img1)
>>> detector_extractor2.detect_and_extract(img2)
>>> matches = match_descriptors(detector_extractor1.descriptors,
...                             detector_extractor2.descriptors)
>>> matches
array([[0, 0],
       [1, 1],
       [2, 2],
       [3, 3],
       [4, 4]])
>>> detector_extractor1.keypoints[matches[:, 0]]
array([[ 42.,  40.],
       [ 47.,  58.],
       [ 44.,  40.],
       [ 59.,  42.],
       [ 45.,  44.]])
>>> detector_extractor2.keypoints[matches[:, 1]]
array([[ 55.,  53.],
       [ 60.,  71.],
       [ 57.,  53.],
       [ 72.,  55.],
       [ 58.,  57.]])

Attributes

__init__(downscale=1.2, n_scales=8, n_keypoints=500, fast_n=9, fast_threshold=0.08, harris_k=0.04)
detect(image)

Detect oriented FAST keypoints along with the corresponding scale.

Parameters:

image : 2D array

Input image.

detect_and_extract(image)

Detect oriented FAST keypoints and extract rBRIEF descriptors.

Note that this is faster than first calling detect and then extract.

Parameters:

image : 2D array

Input image.

extract(image, keypoints, scales, orientations)

Extract rBRIEF binary descriptors for given keypoints in image.

Note that the keypoints must be extracted using the same downscale and n_scales parameters. Additionally, if you want to extract both keypoints and descriptors you should use the faster detect_and_extract.

Parameters:

image : 2D array

Input image.

keypoints : (N, 2) array

Keypoint coordinates as (row, col).

scales : (N, ) array

Corresponding scales.

orientations : (N, ) array

Corresponding orientations in radians.

skimage.feature.blob_dog(image[, min_sigma, ...]) Finds blobs in the given grayscale image.
skimage.feature.blob_doh(image[, min_sigma, ...]) Finds blobs in the given grayscale image.
skimage.feature.blob_log(image[, min_sigma, ...]) Finds blobs in the given grayscale image.
skimage.feature.corner_fast(image[, n, ...]) Extract FAST corners for a given image.
skimage.feature.corner_foerstner(image[, sigma]) Compute Foerstner corner measure response image.
skimage.feature.corner_harris(image[, ...]) Compute Harris corner measure response image.
skimage.feature.corner_kitchen_rosenfeld(image) Compute Kitchen and Rosenfeld corner measure response image.
skimage.feature.corner_moravec Compute Moravec corner measure response image.
skimage.feature.corner_orientations Compute the orientation of corners.
skimage.feature.corner_peaks(image[, ...]) Find corners in corner measure response image.
skimage.feature.corner_shi_tomasi(image[, sigma]) Compute Shi-Tomasi (Kanade-Tomasi) corner measure response image.
skimage.feature.corner_subpix(image, corners) Determine subpixel position of corners.
skimage.feature.daisy(img[, step, radius, ...]) Extract DAISY feature descriptors densely for the given image.
skimage.feature.greycomatrix(image, ...[, ...]) Calculate the grey-level co-occurrence matrix.
skimage.feature.greycoprops(P[, prop]) Calculate texture properties of a GLCM.
skimage.feature.hessian_matrix(image[, ...]) Compute Hessian matrix.
skimage.feature.hessian_matrix_det(image, sigma) Computes the approximate Hessian Determinant over an image.
skimage.feature.hessian_matrix_eigvals(Hxx, ...) Compute Eigen values of Hessian matrix.
skimage.feature.hog(image[, orientations, ...]) Extract Histogram of Oriented Gradients (HOG) for a given image.
skimage.feature.local_binary_pattern(image, P, R) Gray scale and rotation invariant LBP (Local Binary Patterns).
skimage.feature.match_descriptors(...[, ...]) Brute-force matching of descriptors.
skimage.feature.match_template(image, template) Match a template to a 2-D or 3-D image using normalized correlation.
skimage.feature.peak_local_max(image[, ...]) Find peaks in an image, and return them as coordinates or a boolean array.
skimage.feature.plot_matches(ax, image1, ...) Plot matched features.
skimage.feature.structure_tensor(image[, ...]) Compute structure tensor using sum of squared differences.
skimage.feature.structure_tensor_eigvals(...) Compute Eigen values of structure tensor.

blob_dog

skimage.feature.blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0, overlap=0.5)

Finds blobs in the given grayscale image.

Blobs are found using the Difference of Gaussian (DoG) method [R121]. For each blob found, the method returns its coordinates and the standard deviation of the Gaussian kernel that detected the blob.

Parameters:

image : ndarray

Input grayscale image, blobs are assumed to be light on dark background (white on black).

min_sigma : float, optional

The minimum standard deviation for Gaussian Kernel. Keep this low to detect smaller blobs.

max_sigma : float, optional

The maximum standard deviation for Gaussian Kernel. Keep this high to detect larger blobs.

sigma_ratio : float, optional

The ratio between the standard deviation of Gaussian Kernels used for computing the Difference of Gaussians

threshold : float, optional.

The absolute lower bound for scale space maxima. Local maxima smaller than thresh are ignored. Reduce this to detect blobs with less intensities.

overlap : float, optional

A value between 0 and 1. If the area of two blobs overlaps by a fraction greater than threshold, the smaller blob is eliminated.

Returns:

A : (n, 3) ndarray

A 2d array with each row representing 3 values, (y,x,sigma) where (y,x) are coordinates of the blob and sigma is the standard deviation of the Gaussian kernel which detected the blob.

Notes

The radius of each blob is approximately \sqrt{2}sigma.

References

[R121](1, 2) http://en.wikipedia.org/wiki/Blob_detection#The_difference_of_Gaussians_approach

Examples

>>> from skimage import data, feature
>>> feature.blob_dog(data.coins(), threshold=.5, max_sigma=40)
array([[ 45, 336,  16],
       [ 52, 155,  16],
       [ 52, 216,  16],
       [ 54,  42,  16],
       [ 54, 276,  10],
       [ 58, 100,  10],
       [120, 272,  16],
       [124, 337,  10],
       [125,  45,  16],
       [125, 208,  10],
       [127, 102,  10],
       [128, 154,  10],
       [185, 347,  16],
       [193, 213,  16],
       [194, 277,  16],
       [195, 102,  16],
       [196,  43,  10],
       [198, 155,  10],
       [260,  46,  16],
       [261, 173,  16],
       [263, 245,  16],
       [263, 302,  16],
       [267, 115,  10],
       [267, 359,  16]])

blob_doh

skimage.feature.blob_doh(image, min_sigma=1, max_sigma=30, num_sigma=10, threshold=0.01, overlap=0.5, log_scale=False)

Finds blobs in the given grayscale image.

Blobs are found using the Determinant of Hessian method [R122]. For each blob found, the method returns its coordinates and the standard deviation of the Gaussian Kernel used for the Hessian matrix whose determinant detected the blob. Determinant of Hessians is approximated using [R123].

Parameters:

image : ndarray

Input grayscale image.Blobs can either be light on dark or vice versa.

min_sigma : float, optional

The minimum standard deviation for Gaussian Kernel used to compute Hessian matrix. Keep this low to detect smaller blobs.

max_sigma : float, optional

The maximum standard deviation for Gaussian Kernel used to compute Hessian matrix. Keep this high to detect larger blobs.

num_sigma : int, optional

The number of intermediate values of standard deviations to consider between min_sigma and max_sigma.

threshold : float, optional.

The absolute lower bound for scale space maxima. Local maxima smaller than thresh are ignored. Reduce this to detect less prominent blobs.

overlap : float, optional

A value between 0 and 1. If the area of two blobs overlaps by a fraction greater than threshold, the smaller blob is eliminated.

log_scale : bool, optional

If set intermediate values of standard deviations are interpolated using a logarithmic scale to the base 10. If not, linear interpolation is used.

Returns:

A : (n, 3) ndarray

A 2d array with each row representing 3 values, (y,x,sigma) where (y,x) are coordinates of the blob and sigma is the standard deviation of the Gaussian kernel of the Hessian Matrix whose determinant detected the blob.

Notes

The radius of each blob is approximately sigma. Computation of Determinant of Hessians is independent of the standard deviation. Therefore detecting larger blobs won’t take more time. In methods line blob_dog() and blob_log() the computation of Gaussians for larger sigma takes more time. The downside is that this method can’t be used for detecting blobs of radius less than 3px due to the box filters used in the approximation of Hessian Determinant.

References

[R122](1, 2) http://en.wikipedia.org/wiki/Blob_detection#The_determinant_of_the_Hessian
[R123](1, 2) Herbert Bay, Andreas Ess, Tinne Tuytelaars, Luc Van Gool, “SURF: Speeded Up Robust Features” ftp://ftp.vision.ee.ethz.ch/publications/articles/eth_biwi_00517.pdf

Examples

>>> from skimage import data, feature
>>> img = data.coins()
>>> feature.blob_doh(img)
array([[121, 271,  30],
       [123,  44,  23],
       [123, 205,  20],
       [124, 336,  20],
       [126, 101,  20],
       [126, 153,  20],
       [156, 302,  30],
       [185, 348,  30],
       [192, 212,  23],
       [193, 275,  23],
       [195, 100,  23],
       [197,  44,  20],
       [197, 153,  20],
       [260, 173,  30],
       [262, 243,  23],
       [265, 113,  23],
       [270, 363,  30]])

blob_log

skimage.feature.blob_log(image, min_sigma=1, max_sigma=50, num_sigma=10, threshold=0.2, overlap=0.5, log_scale=False)

Finds blobs in the given grayscale image.

Blobs are found using the Laplacian of Gaussian (LoG) method [R124]. For each blob found, the method returns its coordinates and the standard deviation of the Gaussian kernel that detected the blob.

Parameters:

image : ndarray

Input grayscale image, blobs are assumed to be light on dark background (white on black).

min_sigma : float, optional

The minimum standard deviation for Gaussian Kernel. Keep this low to detect smaller blobs.

max_sigma : float, optional

The maximum standard deviation for Gaussian Kernel. Keep this high to detect larger blobs.

num_sigma : int, optional

The number of intermediate values of standard deviations to consider between min_sigma and max_sigma.

threshold : float, optional.

The absolute lower bound for scale space maxima. Local maxima smaller than thresh are ignored. Reduce this to detect blobs with less intensities.

overlap : float, optional

A value between 0 and 1. If the area of two blobs overlaps by a fraction greater than threshold, the smaller blob is eliminated.

log_scale : bool, optional

If set intermediate values of standard deviations are interpolated using a logarithmic scale to the base 10. If not, linear interpolation is used.

Returns:

A : (n, 3) ndarray

A 2d array with each row representing 3 values, (y,x,sigma) where (y,x) are coordinates of the blob and sigma is the standard deviation of the Gaussian kernel which detected the blob.

Notes

The radius of each blob is approximately \sqrt{2}sigma.

References

[R124](1, 2) http://en.wikipedia.org/wiki/Blob_detection#The_Laplacian_of_Gaussian

Examples

>>> from skimage import data, feature, exposure
>>> img = data.coins()
>>> img = exposure.equalize_hist(img)  # improves detection
>>> feature.blob_log(img, threshold = .3)
array([[113, 323,   1],
       [121, 272,  17],
       [124, 336,  11],
       [126,  46,  11],
       [126, 208,  11],
       [127, 102,  11],
       [128, 154,  11],
       [185, 344,  17],
       [194, 213,  17],
       [194, 276,  17],
       [197,  44,  11],
       [198, 103,  11],
       [198, 155,  11],
       [260, 174,  17],
       [263, 244,  17],
       [263, 302,  17],
       [266, 115,  11]])

corner_fast

skimage.feature.corner_fast(image, n=12, threshold=0.15)

Extract FAST corners for a given image.

Parameters:

image : 2D ndarray

Input image.

n : int

Minimum number of consecutive pixels out of 16 pixels on the circle that should all be either brighter or darker w.r.t testpixel. A point c on the circle is darker w.r.t test pixel p if Ic < Ip - threshold and brighter if Ic > Ip + threshold. Also stands for the n in FAST-n corner detector.

threshold : float

Threshold used in deciding whether the pixels on the circle are brighter, darker or similar w.r.t. the test pixel. Decrease the threshold when more corners are desired and vice-versa.

Returns:

response : ndarray

FAST corner response image.

References

[R125]Edward Rosten and Tom Drummond “Machine Learning for high-speed corner detection”, http://www.edwardrosten.com/work/rosten_2006_machine.pdf
[R126]Wikipedia, “Features from accelerated segment test”, https://en.wikipedia.org/wiki/Features_from_accelerated_segment_test

Examples

>>> from skimage.feature import corner_fast, corner_peaks
>>> square = np.zeros((12, 12))
>>> square[3:9, 3:9] = 1
>>> square.astype(int)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> corner_peaks(corner_fast(square, 9), min_distance=1)
array([[3, 3],
       [3, 8],
       [8, 3],
       [8, 8]])

corner_foerstner

skimage.feature.corner_foerstner(image, sigma=1)

Compute Foerstner corner measure response image.

This corner detector uses information from the auto-correlation matrix A:

A = [(imx**2)   (imx*imy)] = [Axx Axy]
    [(imx*imy)   (imy**2)]   [Axy Ayy]

Where imx and imy are the first derivatives averaged with a gaussian filter. The corner measure is then defined as:

w = det(A) / trace(A)           (size of error ellipse)
q = 4 * det(A) / trace(A)**2    (roundness of error ellipse)
Parameters:

image : ndarray

Input image.

sigma : float, optional

Standard deviation used for the Gaussian kernel, which is used as weighting function for the auto-correlation matrix.

Returns:

w : ndarray

Error ellipse sizes.

q : ndarray

Roundness of error ellipse.

References

[R127]http://www.ipb.uni-bonn.de/uploads/tx_ikgpublication/foerstner87.fast.pdf
[R128]http://en.wikipedia.org/wiki/Corner_detection

Examples

>>> from skimage.feature import corner_foerstner, corner_peaks
>>> square = np.zeros([10, 10])
>>> square[2:8, 2:8] = 1
>>> square.astype(int)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> w, q = corner_foerstner(square)
>>> accuracy_thresh = 0.5
>>> roundness_thresh = 0.3
>>> foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w
>>> corner_peaks(foerstner, min_distance=1)
array([[2, 2],
       [2, 7],
       [7, 2],
       [7, 7]])

corner_harris

skimage.feature.corner_harris(image, method='k', k=0.05, eps=1e-06, sigma=1)

Compute Harris corner measure response image.

This corner detector uses information from the auto-correlation matrix A:

A = [(imx**2)   (imx*imy)] = [Axx Axy]
    [(imx*imy)   (imy**2)]   [Axy Ayy]

Where imx and imy are the first derivatives averaged with a gaussian filter. The corner measure is then defined as:

det(A) - k * trace(A)**2

or:

2 * det(A) / (trace(A) + eps)
Parameters:

image : ndarray

Input image.

method : {‘k’, ‘eps’}, optional

Method to compute the response image from the auto-correlation matrix.

k : float, optional

Sensitivity factor to separate corners from edges, typically in range [0, 0.2]. Small values of k result in detection of sharp corners.

eps : float, optional

Normalisation factor (Noble’s corner measure).

sigma : float, optional

Standard deviation used for the Gaussian kernel, which is used as weighting function for the auto-correlation matrix.

Returns:

response : ndarray

Harris response image.

References

[R129]http://kiwi.cs.dal.ca/~dparks/CornerDetection/harris.htm
[R130]http://en.wikipedia.org/wiki/Corner_detection

Examples

>>> from skimage.feature import corner_harris, corner_peaks
>>> square = np.zeros([10, 10])
>>> square[2:8, 2:8] = 1
>>> square.astype(int)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> corner_peaks(corner_harris(square), min_distance=1)
array([[2, 2],
       [2, 7],
       [7, 2],
       [7, 7]])

corner_kitchen_rosenfeld

skimage.feature.corner_kitchen_rosenfeld(image, mode='constant', cval=0)

Compute Kitchen and Rosenfeld corner measure response image.

The corner measure is calculated as follows:

(imxx * imy**2 + imyy * imx**2 - 2 * imxy * imx * imy)
    / (imx**2 + imy**2)

Where imx and imy are the first and imxx, imxy, imyy the second derivatives.

Parameters:

image : ndarray

Input image.

mode : {‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional

How to handle values outside the image borders.

cval : float, optional

Used in conjunction with mode ‘constant’, the value outside the image boundaries.

Returns:

response : ndarray

Kitchen and Rosenfeld response image.

corner_moravec

skimage.feature.corner_moravec()

Compute Moravec corner measure response image.

This is one of the simplest corner detectors and is comparatively fast but has several limitations (e.g. not rotation invariant).

Parameters:

image : ndarray

Input image.

window_size : int, optional (default 1)

Window size.

Returns:

response : ndarray

Moravec response image.

References

[R131]http://kiwi.cs.dal.ca/~dparks/CornerDetection/moravec.htm
[R132]http://en.wikipedia.org/wiki/Corner_detection

Examples

>>> from skimage.feature import corner_moravec
>>> square = np.zeros([7, 7])
>>> square[3, 3] = 1
>>> square.astype(int)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> corner_moravec(square).astype(int)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 2, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])

corner_orientations

skimage.feature.corner_orientations()

Compute the orientation of corners.

The orientation of corners is computed using the first order central moment i.e. the center of mass approach. The corner orientation is the angle of the vector from the corner coordinate to the intensity centroid in the local neighborhood around the corner calculated using first order central moment.

Parameters:

image : 2D array

Input grayscale image.

corners : (N, 2) array

Corner coordinates as (row, col).

mask : 2D array

Mask defining the local neighborhood of the corner used for the calculation of the central moment.

Returns:

orientations : (N, 1) array

Orientations of corners in the range [-pi, pi].

References

[R133]Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski “ORB : An efficient alternative to SIFT and SURF” http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf
[R134]Paul L. Rosin, “Measuring Corner Properties” http://users.cs.cf.ac.uk/Paul.Rosin/corner2.pdf

Examples

>>> from skimage.morphology import octagon
>>> from skimage.feature import (corner_fast, corner_peaks,
...                              corner_orientations)
>>> square = np.zeros((12, 12))
>>> square[3:9, 3:9] = 1
>>> square.astype(int)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> corners = corner_peaks(corner_fast(square, 9), min_distance=1)
>>> corners
array([[3, 3],
       [3, 8],
       [8, 3],
       [8, 8]])
>>> orientations = corner_orientations(square, corners, octagon(3, 2))
>>> np.rad2deg(orientations)
array([  45.,  135.,  -45., -135.])

corner_peaks

skimage.feature.corner_peaks(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, exclude_border=True, indices=True, num_peaks=inf, footprint=None, labels=None)

Find corners in corner measure response image.

This differs from skimage.feature.peak_local_max in that it suppresses multiple connected peaks with the same accumulator value.

Parameters:

* : *

Examples

>>> from skimage.feature import peak_local_max
>>> response = np.zeros((5, 5))
>>> response[2:4, 2:4] = 1
>>> response
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  1.,  0.],
       [ 0.,  0.,  1.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> peak_local_max(response, exclude_border=False)
array([[2, 2],
       [2, 3],
       [3, 2],
       [3, 3]])
>>> corner_peaks(response, exclude_border=False)
array([[2, 2]])
>>> corner_peaks(response, exclude_border=False, min_distance=0)
array([[2, 2],
       [2, 3],
       [3, 2],
       [3, 3]])

corner_shi_tomasi

skimage.feature.corner_shi_tomasi(image, sigma=1)

Compute Shi-Tomasi (Kanade-Tomasi) corner measure response image.

This corner detector uses information from the auto-correlation matrix A:

A = [(imx**2)   (imx*imy)] = [Axx Axy]
    [(imx*imy)   (imy**2)]   [Axy Ayy]

Where imx and imy are the first derivatives averaged with a gaussian filter. The corner measure is then defined as the smaller eigenvalue of A:

((Axx + Ayy) - sqrt((Axx - Ayy)**2 + 4 * Axy**2)) / 2
Parameters:

image : ndarray

Input image.

sigma : float, optional

Standard deviation used for the Gaussian kernel, which is used as weighting function for the auto-correlation matrix.

Returns:

response : ndarray

Shi-Tomasi response image.

References

[R135]http://kiwi.cs.dal.ca/~dparks/CornerDetection/harris.htm
[R136]http://en.wikipedia.org/wiki/Corner_detection

Examples

>>> from skimage.feature import corner_shi_tomasi, corner_peaks
>>> square = np.zeros([10, 10])
>>> square[2:8, 2:8] = 1
>>> square.astype(int)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> corner_peaks(corner_shi_tomasi(square), min_distance=1)
array([[2, 2],
       [2, 7],
       [7, 2],
       [7, 7]])

corner_subpix

skimage.feature.corner_subpix(image, corners, window_size=11, alpha=0.99)

Determine subpixel position of corners.

Parameters:

image : ndarray

Input image.

corners : (N, 2) ndarray

Corner coordinates (row, col).

window_size : int, optional

Search window size for subpixel estimation.

alpha : float, optional

Significance level for point classification.

Returns:

positions : (N, 2) ndarray

Subpixel corner positions. NaN for “not classified” corners.

References

[R137]http://www.ipb.uni-bonn.de/uploads/tx_ikgpublication/ foerstner87.fast.pdf
[R138]http://en.wikipedia.org/wiki/Corner_detection

Examples

>>> from skimage.feature import corner_harris, corner_peaks, corner_subpix
>>> img = np.zeros((10, 10))
>>> img[:5, :5] = 1
>>> img[5:, 5:] = 1
>>> img.astype(int)
array([[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]])
>>> coords = corner_peaks(corner_harris(img), min_distance=2)
>>> coords_subpix = corner_subpix(img, coords, window_size=7)
>>> coords_subpix
array([[ 4.5,  4.5]])

daisy

skimage.feature.daisy(img, step=4, radius=15, rings=3, histograms=8, orientations=8, normalization='l1', sigmas=None, ring_radii=None, visualize=False)

Extract DAISY feature descriptors densely for the given image.

DAISY is a feature descriptor similar to SIFT formulated in a way that allows for fast dense extraction. Typically, this is practical for bag-of-features image representations.

The implementation follows Tola et al. [R139] but deviate on the following points:

  • Histogram bin contribution are smoothed with a circular Gaussian window over the tonal range (the angular range).
  • The sigma values of the spatial Gaussian smoothing in this code do not match the sigma values in the original code by Tola et al. [R140]. In their code, spatial smoothing is applied to both the input image and the center histogram. However, this smoothing is not documented in [R139] and, therefore, it is omitted.
Parameters:

img : (M, N) array

Input image (greyscale).

step : int, optional

Distance between descriptor sampling points.

radius : int, optional

Radius (in pixels) of the outermost ring.

rings : int, optional

Number of rings.

histograms : int, optional

Number of histograms sampled per ring.

orientations : int, optional

Number of orientations (bins) per histogram.

normalization : [ ‘l1’ | ‘l2’ | ‘daisy’ | ‘off’ ], optional

How to normalize the descriptors

  • ‘l1’: L1-normalization of each descriptor.
  • ‘l2’: L2-normalization of each descriptor.
  • ‘daisy’: L2-normalization of individual histograms.
  • ‘off’: Disable normalization.

sigmas : 1D array of float, optional

Standard deviation of spatial Gaussian smoothing for the center histogram and for each ring of histograms. The array of sigmas should be sorted from the center and out. I.e. the first sigma value defines the spatial smoothing of the center histogram and the last sigma value defines the spatial smoothing of the outermost ring. Specifying sigmas overrides the following parameter.

rings = len(sigmas) - 1

ring_radii : 1D array of int, optional

Radius (in pixels) for each ring. Specifying ring_radii overrides the following two parameters.

rings = len(ring_radii) radius = ring_radii[-1]

If both sigmas and ring_radii are given, they must satisfy the following predicate since no radius is needed for the center histogram.

len(ring_radii) == len(sigmas) + 1

visualize : bool, optional

Generate a visualization of the DAISY descriptors

Returns:

descs : array

Grid of DAISY descriptors for the given image as an array dimensionality (P, Q, R) where

P = ceil((M - radius*2) / step) Q = ceil((N - radius*2) / step) R = (rings * histograms + 1) * orientations

descs_img : (M, N, 3) array (only if visualize==True)

Visualization of the DAISY descriptors.

References

[R139](1, 2, 3) Tola et al. “Daisy: An efficient dense descriptor applied to wide- baseline stereo.” Pattern Analysis and Machine Intelligence, IEEE Transactions on 32.5 (2010): 815-830.
[R140](1, 2) http://cvlab.epfl.ch/alumni/tola/daisy.html

greycomatrix

skimage.feature.greycomatrix(image, distances, angles, levels=256, symmetric=False, normed=False)

Calculate the grey-level co-occurrence matrix.

A grey level co-occurence matrix is a histogram of co-occuring greyscale values at a given offset over an image.

Parameters:

image : array_like of uint8

Integer typed input image. The image will be cast to uint8, so the maximum value must be less than 256.

distances : array_like

List of pixel pair distance offsets.

angles : array_like

List of pixel pair angles in radians.

levels : int, optional

The input image should contain integers in [0, levels-1], where levels indicate the number of grey-levels counted (typically 256 for an 8-bit image). The maximum value is 256.

symmetric : bool, optional

If True, the output matrix P[:, :, d, theta] is symmetric. This is accomplished by ignoring the order of value pairs, so both (i, j) and (j, i) are accumulated when (i, j) is encountered for a given offset. The default is False.

normed : bool, optional

If True, normalize each matrix P[:, :, d, theta] by dividing by the total number of accumulated co-occurrences for the given offset. The elements of the resulting matrix sum to 1. The default is False.

Returns:

P : 4-D ndarray

The grey-level co-occurrence histogram. The value P[i,j,d,theta] is the number of times that grey-level j occurs at a distance d and at an angle theta from grey-level i. If normed is False, the output is of type uint32, otherwise it is float64.

References

[R141]The GLCM Tutorial Home Page, http://www.fp.ucalgary.ca/mhallbey/tutorial.htm
[R142]Pattern Recognition Engineering, Morton Nadler & Eric P. Smith
[R143]Wikipedia, http://en.wikipedia.org/wiki/Co-occurrence_matrix

Examples

Compute 2 GLCMs: One for a 1-pixel offset to the right, and one for a 1-pixel offset upwards.

>>> image = np.array([[0, 0, 1, 1],
...                   [0, 0, 1, 1],
...                   [0, 2, 2, 2],
...                   [2, 2, 3, 3]], dtype=np.uint8)
>>> result = greycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=4)
>>> result[:, :, 0, 0]
array([[2, 2, 1, 0],
       [0, 2, 0, 0],
       [0, 0, 3, 1],
       [0, 0, 0, 1]], dtype=uint32)
>>> result[:, :, 0, 1]
array([[1, 1, 3, 0],
       [0, 1, 1, 0],
       [0, 0, 0, 2],
       [0, 0, 0, 0]], dtype=uint32)
>>> result[:, :, 0, 2]
array([[3, 0, 2, 0],
       [0, 2, 2, 0],
       [0, 0, 1, 2],
       [0, 0, 0, 0]], dtype=uint32)
>>> result[:, :, 0, 3]
array([[2, 0, 0, 0],
       [1, 1, 2, 0],
       [0, 0, 2, 1],
       [0, 0, 0, 0]], dtype=uint32)

greycoprops

skimage.feature.greycoprops(P, prop='contrast')

Calculate texture properties of a GLCM.

Compute a feature of a grey level co-occurrence matrix to serve as a compact summary of the matrix. The properties are computed as follows:

  • ‘contrast’: \sum_{i,j=0}^{levels-1} P_{i,j}(i-j)^2

  • ‘dissimilarity’: \sum_{i,j=0}^{levels-1}P_{i,j}|i-j|

  • ‘homogeneity’: \sum_{i,j=0}^{levels-1}\frac{P_{i,j}}{1+(i-j)^2}

  • ‘ASM’: \sum_{i,j=0}^{levels-1} P_{i,j}^2

  • ‘energy’: \sqrt{ASM}

  • ‘correlation’:

    \sum_{i,j=0}^{levels-1} P_{i,j}\left[\frac{(i-\mu_i) \ (j-\mu_j)}{\sqrt{(\sigma_i^2)(\sigma_j^2)}}\right]

Parameters:

P : ndarray

Input array. P is the grey-level co-occurrence histogram for which to compute the specified property. The value P[i,j,d,theta] is the number of times that grey-level j occurs at a distance d and at an angle theta from grey-level i.

prop : {‘contrast’, ‘dissimilarity’, ‘homogeneity’, ‘energy’, ‘correlation’, ‘ASM’}, optional

The property of the GLCM to compute. The default is ‘contrast’.

Returns:

results : 2-D ndarray

2-dimensional array. results[d, a] is the property ‘prop’ for the d’th distance and the a’th angle.

References

[R144]The GLCM Tutorial Home Page, http://www.fp.ucalgary.ca/mhallbey/tutorial.htm

Examples

Compute the contrast for GLCMs with distances [1, 2] and angles [0 degrees, 90 degrees]

>>> image = np.array([[0, 0, 1, 1],
...                   [0, 0, 1, 1],
...                   [0, 2, 2, 2],
...                   [2, 2, 3, 3]], dtype=np.uint8)
>>> g = greycomatrix(image, [1, 2], [0, np.pi/2], levels=4,
...                  normed=True, symmetric=True)
>>> contrast = greycoprops(g, 'contrast')
>>> contrast
array([[ 0.58333333,  1.        ],
       [ 1.25      ,  2.75      ]])

hessian_matrix

skimage.feature.hessian_matrix(image, sigma=1, mode='constant', cval=0)

Compute Hessian matrix.

The Hessian matrix is defined as:

H = [Hxx Hxy]
    [Hxy Hyy]

which is computed by convolving the image with the second derivatives of the Gaussian kernel in the respective x- and y-directions.

Parameters:

image : ndarray

Input image.

sigma : float

Standard deviation used for the Gaussian kernel, which is used as weighting function for the auto-correlation matrix.

mode : {‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional

How to handle values outside the image borders.

cval : float, optional

Used in conjunction with mode ‘constant’, the value outside the image boundaries.

Returns:

Hxx : ndarray

Element of the Hessian matrix for each pixel in the input image.

Hxy : ndarray

Element of the Hessian matrix for each pixel in the input image.

Hyy : ndarray

Element of the Hessian matrix for each pixel in the input image.

Examples

>>> from skimage.feature import hessian_matrix, hessian_matrix_eigvals
>>> square = np.zeros((5, 5))
>>> square[2, 2] = 1
>>> Hxx, Hxy, Hyy = hessian_matrix(square, sigma=0.1)
>>> Hxx
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

hessian_matrix_det

skimage.feature.hessian_matrix_det(image, sigma)

Computes the approximate Hessian Determinant over an image.

This method uses box filters over integral images to compute the approximate Hessian Determinant as described in [R145].

Parameters:

image : array

The image over which to compute Hessian Determinant.

sigma : float

Standard deviation used for the Gaussian kernel, used for the Hessian matrix.

Returns:

out : array

The array of the Determinant of Hessians.

Notes

The running time of this method only depends on size of the image. It is independent of sigma as one would expect. The downside is that the result for sigma less than 3 is not accurate, i.e., not similar to the result obtained if someone computed the Hessian and took it’s determinant.

References

[R145](1, 2) Herbert Bay, Andreas Ess, Tinne Tuytelaars, Luc Van Gool, “SURF: Speeded Up Robust Features” ftp://ftp.vision.ee.ethz.ch/publications/articles/eth_biwi_00517.pdf

hessian_matrix_eigvals

skimage.feature.hessian_matrix_eigvals(Hxx, Hxy, Hyy)

Compute Eigen values of Hessian matrix.

Parameters:

Hxx : ndarray

Element of the Hessian matrix for each pixel in the input image.

Hxy : ndarray

Element of the Hessian matrix for each pixel in the input image.

Hyy : ndarray

Element of the Hessian matrix for each pixel in the input image.

Returns:

l1 : ndarray

Larger eigen value for each input matrix.

l2 : ndarray

Smaller eigen value for each input matrix.

Examples

>>> from skimage.feature import hessian_matrix, hessian_matrix_eigvals
>>> square = np.zeros((5, 5))
>>> square[2, 2] = 1
>>> Hxx, Hxy, Hyy = hessian_matrix(square, sigma=0.1)
>>> hessian_matrix_eigvals(Hxx, Hxy, Hyy)[0]
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

hog

skimage.feature.hog(image, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(3, 3), visualise=False, normalise=False)

Extract Histogram of Oriented Gradients (HOG) for a given image.

Compute a Histogram of Oriented Gradients (HOG) by

  1. (optional) global image normalisation
  2. computing the gradient image in x and y
  3. computing gradient histograms
  4. normalising across blocks
  5. flattening into a feature vector
Parameters:

image : (M, N) ndarray

Input image (greyscale).

orientations : int

Number of orientation bins.

pixels_per_cell : 2 tuple (int, int)

Size (in pixels) of a cell.

cells_per_block : 2 tuple (int,int)

Number of cells in each block.

visualise : bool, optional

Also return an image of the HOG.

normalise : bool, optional

Apply power law compression to normalise the image before processing.

Returns:

newarr : ndarray

HOG for the image as a 1D (flattened) array.

hog_image : ndarray (if visualise=True)

A visualisation of the HOG image.

References

local_binary_pattern

skimage.feature.local_binary_pattern(image, P, R, method='default')

Gray scale and rotation invariant LBP (Local Binary Patterns).

LBP is an invariant descriptor that can be used for texture classification.

Parameters:

image : (N, M) array

Graylevel image.

P : int

Number of circularly symmetric neighbour set points (quantization of the angular space).

R : float

Radius of circle (spatial resolution of the operator).

method : {‘default’, ‘ror’, ‘uniform’, ‘var’}

Method to determine the pattern.

  • ‘default’: original local binary pattern which is gray scale but not

    rotation invariant.

  • ‘ror’: extension of default implementation which is gray scale and

    rotation invariant.

  • ‘uniform’: improved rotation invariance with uniform patterns and

    finer quantization of the angular space which is gray scale and rotation invariant.

  • ‘nri_uniform’: non rotation-invariant uniform patterns variant

    which is only gray scale invariant [2].

  • ‘var’: rotation invariant variance measures of the contrast of local

    image texture which is rotation but not gray scale invariant.

Returns:

output : (N, M) array

LBP image.

References

[R146]Multiresolution Gray-Scale and Rotation Invariant Texture Classification with Local Binary Patterns. Timo Ojala, Matti Pietikainen, Topi Maenpaa. http://www.rafbis.it/biplab15/images/stories/docenti/Danielriccio/ Articoliriferimento/LBP.pdf, 2002.
[R147]Face recognition with local binary patterns. Timo Ahonen, Abdenour Hadid, Matti Pietikainen, http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.214.6851, 2004.

match_descriptors

skimage.feature.match_descriptors(descriptors1, descriptors2, metric=None, p=2, max_distance=inf, cross_check=True)

Brute-force matching of descriptors.

For each descriptor in the first set this matcher finds the closest descriptor in the second set (and vice-versa in the case of enabled cross-checking).

Parameters:

descriptors1 : (M, P) array

Binary descriptors of size P about M keypoints in the first image.

descriptors2 : (N, P) array

Binary descriptors of size P about N keypoints in the second image.

metric : {‘euclidean’, ‘cityblock’, ‘minkowski’, ‘hamming’, ...}

The metric to compute the distance between two descriptors. See scipy.spatial.distance.cdist for all possible types. The hamming distance should be used for binary descriptors. By default the L2-norm is used for all descriptors of dtype float or double and the Hamming distance is used for binary descriptors automatically.

p : int

The p-norm to apply for metric='minkowski'.

max_distance : float

Maximum allowed distance between descriptors of two keypoints in separate images to be regarded as a match.

cross_check : bool

If True, the matched keypoints are returned after cross checking i.e. a matched pair (keypoint1, keypoint2) is returned if keypoint2 is the best match for keypoint1 in second image and keypoint1 is the best match for keypoint2 in first image.

Returns:

matches : (Q, 2) array

Indices of corresponding matches in first and second set of descriptors, where matches[:, 0] denote the indices in the first and matches[:, 1] the indices in the second set of descriptors.

match_template

skimage.feature.match_template(image, template, pad_input=False, mode='constant', constant_values=0)

Match a template to a 2-D or 3-D image using normalized correlation.

The output is an array with values between -1.0 and 1.0. The value at a given position corresponds to the correlation coefficient between the image and the template.

For pad_input=True matches correspond to the center and otherwise to the top-left corner of the template. To find the best match you must search for peaks in the response (output) image.

Parameters:

image : (M, N[, D]) array

2-D or 3-D input image.

template : (m, n[, d]) array

Template to locate. It must be (m <= M, n <= N[, d <= D]).

pad_input : bool

If True, pad image so that output is the same size as the image, and output values correspond to the template center. Otherwise, the output is an array with shape (M - m + 1, N - n + 1) for an (M, N) image and an (m, n) template, and matches correspond to origin (top-left corner) of the template.

mode : see numpy.pad, optional

Padding mode.

constant_values : see numpy.pad, optional

Constant values used in conjunction with mode='constant'.

Returns:

output : array

Response image with correlation coefficients.

References

[R148]Briechle and Hanebeck, “Template Matching using Fast Normalized Cross Correlation”, Proceedings of the SPIE (2001).
[R149]J. P. Lewis, “Fast Normalized Cross-Correlation”, Industrial Light and Magic.

Examples

>>> template = np.zeros((3, 3))
>>> template[1, 1] = 1
>>> template
array([[ 0.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  0.]])
>>> image = np.zeros((6, 6))
>>> image[1, 1] = 1
>>> image[4, 4] = -1
>>> image
array([[ 0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0., -1.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.]])
>>> result = match_template(image, template)
>>> np.round(result, 3)
array([[ 1.   , -0.125,  0.   ,  0.   ],
       [-0.125, -0.125,  0.   ,  0.   ],
       [ 0.   ,  0.   ,  0.125,  0.125],
       [ 0.   ,  0.   ,  0.125, -1.   ]], dtype=float32)
>>> result = match_template(image, template, pad_input=True)
>>> np.round(result, 3)
array([[-0.125, -0.125, -0.125,  0.   ,  0.   ,  0.   ],
       [-0.125,  1.   , -0.125,  0.   ,  0.   ,  0.   ],
       [-0.125, -0.125, -0.125,  0.   ,  0.   ,  0.   ],
       [ 0.   ,  0.   ,  0.   ,  0.125,  0.125,  0.125],
       [ 0.   ,  0.   ,  0.   ,  0.125, -1.   ,  0.125],
       [ 0.   ,  0.   ,  0.   ,  0.125,  0.125,  0.125]], dtype=float32)

peak_local_max

skimage.feature.peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, exclude_border=True, indices=True, num_peaks=inf, footprint=None, labels=None)

Find peaks in an image, and return them as coordinates or a boolean array.

Peaks are the local maxima in a region of 2 * min_distance + 1 (i.e. peaks are separated by at least min_distance).

NOTE: If peaks are flat (i.e. multiple adjacent pixels have identical intensities), the coordinates of all such pixels are returned.

Parameters:

image : ndarray of floats

Input image.

min_distance : int

Minimum number of pixels separating peaks in a region of 2 * min_distance + 1 (i.e. peaks are separated by at least min_distance). If exclude_border is True, this value also excludes a border min_distance from the image boundary. To find the maximum number of peaks, use min_distance=1.

threshold_abs : float

Minimum intensity of peaks.

threshold_rel : float

Minimum intensity of peaks calculated as max(image) * threshold_rel.

exclude_border : bool

If True, min_distance excludes peaks from the border of the image as well as from each other.

indices : bool

If True, the output will be an array representing peak coordinates. If False, the output will be a boolean array shaped as image.shape with peaks present at True elements.

num_peaks : int

Maximum number of peaks. When the number of peaks exceeds num_peaks, return num_peaks peaks based on highest peak intensity.

footprint : ndarray of bools, optional

If provided, footprint == 1 represents the local region within which to search for peaks at every point in image. Overrides min_distance, except for border exclusion if exclude_border=True.

labels : ndarray of ints, optional

If provided, each unique region labels == value represents a unique region to search for peaks. Zero is reserved for background.

Returns:

output : ndarray or ndarray of bools

  • If indices = True : (row, column, ...) coordinates of peaks.
  • If indices = False : Boolean array shaped like image, with peaks represented by True values.

Notes

The peak local maximum function returns the coordinates of local peaks (maxima) in a image. A maximum filter is used for finding local maxima. This operation dilates the original image. After comparison between dilated and original image, peak_local_max function returns the coordinates of peaks where dilated image = original.

Examples

>>> img1 = np.zeros((7, 7))
>>> img1[3, 4] = 1
>>> img1[3, 2] = 1.5
>>> img1
array([[ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  1.5,  0. ,  1. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ]])
>>> peak_local_max(img1, min_distance=1)
array([[3, 2],
       [3, 4]])
>>> peak_local_max(img1, min_distance=2)
array([[3, 2]])
>>> img2 = np.zeros((20, 20, 20))
>>> img2[10, 10, 10] = 1
>>> peak_local_max(img2, exclude_border=False)
array([[10, 10, 10]])

plot_matches

skimage.feature.plot_matches(ax, image1, image2, keypoints1, keypoints2, matches, keypoints_color='k', matches_color=None, only_matches=False)

Plot matched features.

Parameters:

ax : matplotlib.axes.Axes

Matches and image are drawn in this ax.

image1 : (N, M [, 3]) array

First grayscale or color image.

image2 : (N, M [, 3]) array

Second grayscale or color image.

keypoints1 : (K1, 2) array

First keypoint coordinates as (row, col).

keypoints2 : (K2, 2) array

Second keypoint coordinates as (row, col).

matches : (Q, 2) array

Indices of corresponding matches in first and second set of descriptors, where matches[:, 0] denote the indices in the first and matches[:, 1] the indices in the second set of descriptors.

keypoints_color : matplotlib color, optional

Color for keypoint locations.

matches_color : matplotlib color, optional

Color for lines which connect keypoint matches. By default the color is chosen randomly.

only_matches : bool, optional

Whether to only plot matches and not plot the keypoint locations.

structure_tensor

skimage.feature.structure_tensor(image, sigma=1, mode='constant', cval=0)

Compute structure tensor using sum of squared differences.

The structure tensor A is defined as:

A = [Axx Axy]
    [Axy Ayy]

which is approximated by the weighted sum of squared differences in a local window around each pixel in the image.

Parameters:

image : ndarray

Input image.

sigma : float

Standard deviation used for the Gaussian kernel, which is used as a weighting function for the local summation of squared differences.

mode : {‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional

How to handle values outside the image borders.

cval : float, optional

Used in conjunction with mode ‘constant’, the value outside the image boundaries.

Returns:

Axx : ndarray

Element of the structure tensor for each pixel in the input image.

Axy : ndarray

Element of the structure tensor for each pixel in the input image.

Ayy : ndarray

Element of the structure tensor for each pixel in the input image.

Examples

>>> from skimage.feature import structure_tensor
>>> square = np.zeros((5, 5))
>>> square[2, 2] = 1
>>> Axx, Axy, Ayy = structure_tensor(square, sigma=0.1)
>>> Axx
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  1.,  0.],
       [ 0.,  4.,  0.,  4.,  0.],
       [ 0.,  1.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

structure_tensor_eigvals

skimage.feature.structure_tensor_eigvals(Axx, Axy, Ayy)

Compute Eigen values of structure tensor.

Parameters:

Axx : ndarray

Element of the structure tensor for each pixel in the input image.

Axy : ndarray

Element of the structure tensor for each pixel in the input image.

Ayy : ndarray

Element of the structure tensor for each pixel in the input image.

Returns:

l1 : ndarray

Larger eigen value for each input matrix.

l2 : ndarray

Smaller eigen value for each input matrix.

Examples

>>> from skimage.feature import structure_tensor, structure_tensor_eigvals
>>> square = np.zeros((5, 5))
>>> square[2, 2] = 1
>>> Axx, Axy, Ayy = structure_tensor(square, sigma=0.1)
>>> structure_tensor_eigvals(Axx, Axy, Ayy)[0]
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  2.,  4.,  2.,  0.],
       [ 0.,  4.,  0.,  4.,  0.],
       [ 0.,  2.,  4.,  2.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])