mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-02 21:56:33 +08:00
Add test cases for structure tensor and hessian matrix functions
This commit is contained in:
@@ -126,7 +126,7 @@ def hessian_matrix(image, sigma=1, mode='constant', cval=0):
|
||||
|
||||
# window extent to the left and right, which covers > 99% of the normal
|
||||
# distribution
|
||||
window_ext = np.ceil(3 * sigma)
|
||||
window_ext = max(1, np.ceil(3 * sigma))
|
||||
|
||||
ky, kx = np.mgrid[-window_ext:window_ext + 1, -window_ext:window_ext + 1]
|
||||
|
||||
@@ -134,8 +134,10 @@ def hessian_matrix(image, sigma=1, mode='constant', cval=0):
|
||||
gaussian_exp = np.exp(-(kx ** 2 + ky ** 2) / (2 * sigma ** 2))
|
||||
kernel_xx = 1 / (2 * np.pi * sigma ** 4) * (kx ** 2 / sigma ** 2 - 1)
|
||||
kernel_xx *= gaussian_exp
|
||||
kernel_xx /= kernel_xx.sum()
|
||||
kernel_xy = 1 / (2 * np.pi * sigma ** 6) * (kx * ky)
|
||||
kernel_xy *= gaussian_exp
|
||||
kernel_xy /= kernel_xx.sum()
|
||||
kernel_yy = kernel_xx.transpose()
|
||||
|
||||
Hxx = ndimage.convolve(image, kernel_xx, mode=mode, cval=cval)
|
||||
|
||||
@@ -10,7 +10,50 @@ from skimage.morphology import octagon
|
||||
from skimage.feature import (corner_moravec, corner_harris, corner_shi_tomasi,
|
||||
corner_subpix, peak_local_max, corner_peaks,
|
||||
corner_kitchen_rosenfeld, corner_foerstner,
|
||||
corner_fast, corner_orientations)
|
||||
corner_fast, corner_orientations,
|
||||
structure_tensor, hessian_matrix)
|
||||
|
||||
|
||||
def test_structure_tensor():
|
||||
square = np.zeros((5, 5))
|
||||
square[2, 2] = 1
|
||||
Axx, Axy, Ayy = structure_tensor(square, sigma=0.1)
|
||||
assert_array_equal(Axx, np.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]]))
|
||||
assert_array_equal(Axy, np.array([[ 0, 0, 0, 0, 0],
|
||||
[ 0, 1, 0, -1, 0],
|
||||
[ 0, 0, 0, -0, 0],
|
||||
[ 0, -1, -0, 1, 0],
|
||||
[ 0, 0, 0, 0, 0]]))
|
||||
assert_array_equal(Ayy, np.array([[ 0, 0, 0, 0, 0],
|
||||
[ 0, 1, 4, 1, 0],
|
||||
[ 0, 0, 0, 0, 0],
|
||||
[ 0, 1, 4, 1, 0],
|
||||
[ 0, 0, 0, 0, 0]]))
|
||||
|
||||
|
||||
def test_structure_tensor():
|
||||
square = np.zeros((5, 5))
|
||||
square[2, 2] = 1
|
||||
Hxx, Hxy, Hyy = hessian_matrix(square, sigma=0.1)
|
||||
assert_array_equal(Hxx, np.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]]))
|
||||
assert_array_equal(Hxy, np.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]]))
|
||||
assert_array_equal(Hyy, np.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]]))
|
||||
|
||||
|
||||
def test_square_image():
|
||||
|
||||
Reference in New Issue
Block a user