skimage.feature.greycomatrix(image, ...[, ...]) | Calculate the grey-level co-occurrence matrix. |
skimage.feature.greycoprops(P[, prop]) | Calculate texture properties of a GLCM. |
skimage.feature.harris(image[, ...]) | Return corners from a Harris response image |
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_template(image, template) | Match a template to an image using normalized correlation. |
skimage.feature.peak_local_max(image[, ...]) | Return coordinates of peaks in an image. |
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
distances : array_like
angles : array_like
levels : int, optional
symmetric : bool, optional
normed : bool, optional
|
---|---|
Returns : | P : 4-D ndarray
|
References
[R38] | The GLCM Tutorial Home Page, http://www.fp.ucalgary.ca/mhallbey/tutorial.htm |
[R39] | Pattern Recognition Engineering, Morton Nadler & Eric P. Smith |
[R40] | 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/2], 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([[3, 0, 2, 0],
[0, 2, 2, 0],
[0, 0, 1, 2],
[0, 0, 0, 0]], dtype=uint32)
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}
\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
prop : {‘contrast’, ‘dissimilarity’, ‘homogeneity’, ‘energy’, ‘correlation’, ‘ASM’}, optional
|
---|---|
Returns : | results : 2-D ndarray
|
References
[R41] | 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 ]])
Return corners from a Harris response image
Parameters : | image : ndarray of floats
min_distance : int, optional
threshold : float, optional
eps : float, optional
gaussian_deviation : integer, optional
|
---|---|
Returns : | coordinates : (N, 2) array
Examples : ——- : >>> square = np.zeros([10,10]) : >>> square[2:8,2:8] = 1 : >>> square : array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], :
>>> harris(square, min_distance=1) : Corners of the square : array([[3, 3], :
|
Extract Histogram of Oriented Gradients (HOG) for a given image.
Compute a Histogram of Oriented Gradients (HOG) by
- (optional) global image normalisation
- computing the gradient image in x and y
- computing gradient histograms
- normalising across blocks
- flattening into a feature vector
Parameters : | image : (M, N) ndarray
orientations : int
pixels_per_cell : 2 tuple (int, int)
cells_per_block : 2 tuple (int,int)
visualise : bool, optional
normalise : bool, optional
|
---|---|
Returns : | newarr : ndarray
hog_image : ndarray (if visualise=True)
|
References
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
P : int
R : float
method : {‘default’, ‘ror’, ‘uniform’, ‘var’}
|
---|---|
Returns : | output : (N, M) array
|
References
[R42] | 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. |
Match a template to an image using normalized correlation.
The output is an array with values between -1.0 and 1.0, which correspond to the probability that the template is found at that position.
Parameters : | image : array_like
template : array_like
pad_input : bool
|
---|---|
Returns : | output : ndarray
|
Examples
>>> template = np.zeros((3, 3))
>>> template[1, 1] = 1
>>> print template
[[ 0. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 0.]]
>>> image = np.zeros((6, 6))
>>> image[1, 1] = 1
>>> image[4, 4] = -1
>>> print image
[[ 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)
>>> print np.round(result, 3)
[[ 1. -0.125 0. 0. ]
[-0.125 -0.125 0. 0. ]
[ 0. 0. 0.125 0.125]
[ 0. 0. 0.125 -1. ]]
>>> result = match_template(image, template, pad_input=True)
>>> print np.round(result, 3)
[[-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]]
Return coordinates of peaks in an image.
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 pixels have exact same intensity), the coordinates of all pixels are returned.
Parameters : | image : ndarray of floats
min_distance : int
threshold : float
threshold_abs : float
threshold_rel : float
num_peaks : int
|
---|---|
Returns : | coordinates : (N, 2) array
|
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
>>> im = np.zeros((7, 7))
>>> im[3, 4] = 1
>>> im[3, 2] = 1.5
>>> im
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(im, min_distance=1)
array([[3, 2],
[3, 4]])
>>> peak_local_max(im, min_distance=2)
array([[3, 2]])