Added tests for harris, and small fixes

This commit is contained in:
Nelle Varoquaux
2011-12-23 17:21:55 +01:00
parent 7ff98597e2
commit bc0f77622e
2 changed files with 20 additions and 8 deletions
+4 -6
View File
@@ -22,7 +22,7 @@ def _compute_harris_response(image, eps=1e-6):
Returns
--------
features: (M, 2) ndarray
image: (M, N) ndarray
Harris image response
"""
if len(image.shape) == 3:
@@ -85,12 +85,10 @@ def harris(image, min_distance=10, threshold=0.1, eps=1e-6):
# get coordinates of candidates
candidates = harrisim_t.nonzero()
coords = np.concatenate((candidates[0].reshape((len(candidates[0]), 1)),
candidates[1].reshape((len(candidates[0]), 1))),
axis=1)
coords = np.transpose(candidates)
# ...and their values
candidate_values = [harrisim[c[0]][c[1]] for c in coords]
candidate_values = harrisim[candidates]
# sort candidates
index = np.argsort(candidate_values)
@@ -103,7 +101,7 @@ def harris(image, min_distance=10, threshold=0.1, eps=1e-6):
# select the best points taking min_distance into account
filtered_coords = []
for i in index:
if allowed_locations[coords[i][0]][coords[i][1]] == 1:
if allowed_locations[tuple(coords[i])] == 1:
filtered_coords.append(coords[i])
allowed_locations[
(coords[i][0] - min_distance):(coords[i][0] + min_distance),
+16 -2
View File
@@ -1,8 +1,10 @@
import numpy as np
from skimage.filter import harris
from skimage import data
from skimage import img_as_float
from skimage.filter import harris
class TestHarris():
def test_square_image(self):
@@ -24,5 +26,17 @@ class TestHarris():
im = np.zeros((50, 50))
im[4:8, 4:8] = 1
im = img_as_float(im)
results = harris(im, min_distance=3)
print results
assert (results == np.array([[6, 6]])).all()
def test_rotated_lena(self):
"""
The harris filter should yield the same results with an image and it's
rotation.
"""
im = img_as_float(data.lena().mean(axis=2))
results = harris(im)
assert results == np.array([6, 6])
im_rotated = im.T
results_rotated = harris(im_rotated)
assert (results[:, 0] == results_rotated[:, 1]).all()