Corner detectionΒΆ

Detect corner points using the Harris corner detector and determine subpixel position of corners.

[1]http://en.wikipedia.org/wiki/Corner_detection
[2]http://en.wikipedia.org/wiki/Interest_point_detection
../_images/plot_corner_1.png

from matplotlib import pyplot as plt

from skimage import data
from skimage.feature import corner_harris, corner_subpix, corner_peaks
from skimage.transform import warp, AffineTransform
from skimage.draw import ellipse


tform = AffineTransform(scale=(1.3, 1.1), rotation=1, shear=0.7,
                        translation=(210, 50))
image = warp(data.checkerboard(), tform.inverse, output_shape=(350, 350))
rr, cc = ellipse(310, 175, 10, 100)
image[rr, cc] = 1
image[180:230, 10:60] = 1
image[230:280, 60:110] = 1

coords = corner_peaks(corner_harris(image), min_distance=5)
coords_subpix = corner_subpix(image, coords, window_size=13)

fig, ax = plt.subplots()
ax.imshow(image, interpolation='nearest', cmap=plt.cm.gray)
ax.plot(coords[:, 1], coords[:, 0], '.b', markersize=3)
ax.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15)
ax.axis((0, 350, 350, 0))
plt.show()

STDOUT


        

STDERR


        

Python source code: download (generated using skimage 0.11dev)

IPython Notebook: download (generated using skimage 0.11dev)

ZnJvbSBtYXRwbG90bGliIGltcG9ydCBweXBsb3QgYXMgcGx0Cgpmcm9tIHNraW1hZ2UgaW1wb3J0IGRhdGEKZnJvbSBza2ltYWdlLmZlYXR1cmUgaW1wb3J0IGNvcm5lcl9oYXJyaXMsIGNvcm5lcl9zdWJwaXgsIGNvcm5lcl9wZWFrcwpmcm9tIHNraW1hZ2UudHJhbnNmb3JtIGltcG9ydCB3YXJwLCBBZmZpbmVUcmFuc2Zvcm0KZnJvbSBza2ltYWdlLmRyYXcgaW1wb3J0IGVsbGlwc2UKCgp0Zm9ybSA9IEFmZmluZVRyYW5zZm9ybShzY2FsZT0oMS4zLCAxLjEpLCByb3RhdGlvbj0xLCBzaGVhcj0wLjcsCiAgICAgICAgICAgICAgICAgICAgICAgIHRyYW5zbGF0aW9uPSgyMTAsIDUwKSkKaW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