mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-20 12:40:31 +08:00
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
import numpy as np
|
|
from scipy import ndimage
|
|
from . import peak
|
|
|
|
|
|
def harris(image, eps=1e-6, sigma=1):
|
|
"""Compute Harris response image.
|
|
|
|
Parameters
|
|
----------
|
|
image : ndarray
|
|
Input image.
|
|
eps : float, optional
|
|
Normalisation factor.
|
|
sigma : float, optional
|
|
Standard deviation used for the Gaussian kernel.
|
|
|
|
Returns
|
|
-------
|
|
response : ndarray
|
|
Moravec response image.
|
|
|
|
Examples
|
|
-------
|
|
>>> from skimage.feature import harris, peak_local_max
|
|
>>> square = np.zeros([10, 10])
|
|
>>> square[2:8,2:8] = 1
|
|
>>> square
|
|
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.]])
|
|
>>> peak_local_max(harris(square), min_distance=1)
|
|
array([[3, 3],
|
|
[3, 6],
|
|
[6, 3],
|
|
[6, 6]])
|
|
|
|
"""
|
|
|
|
if image.ndim == 3:
|
|
image = rgb2grey(image)
|
|
|
|
# derivatives
|
|
image = ndimage.gaussian_filter(image, sigma, mode='constant', cval=0)
|
|
imx = ndimage.sobel(image, axis=0, mode='constant', cval=0)
|
|
imy = ndimage.sobel(image, axis=1, mode='constant', cval=0)
|
|
|
|
Wxx = ndimage.gaussian_filter(imx * imx, sigma,
|
|
mode='constant', cval=0)
|
|
Wxy = ndimage.gaussian_filter(imx * imy, sigma,
|
|
mode='constant', cval=0)
|
|
Wyy = ndimage.gaussian_filter(imy * imy, sigma,
|
|
mode='constant', cval=0)
|
|
|
|
# determinant and trace
|
|
Wdet = Wxx * Wyy - Wxy**2
|
|
Wtr = Wxx + Wyy
|
|
|
|
# Alternate formula for Harris response.
|
|
# Alison Noble, "Descriptions of Image Surfaces", PhD thesis (1989)
|
|
harris = Wdet / (Wtr + eps)
|
|
|
|
return harris
|