From f95e93669658d586eccaf9dc00f144a8d48c036f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 16 Sep 2012 15:39:25 +0200 Subject: [PATCH] Refactor corner detection example --- doc/examples/plot_corner.py | 38 +++++++++++++++++++++++++++++++++ doc/examples/plot_harris.py | 42 ------------------------------------- 2 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 doc/examples/plot_corner.py delete mode 100644 doc/examples/plot_harris.py diff --git a/doc/examples/plot_corner.py b/doc/examples/plot_corner.py new file mode 100644 index 00000000..7c9caa34 --- /dev/null +++ b/doc/examples/plot_corner.py @@ -0,0 +1,38 @@ +""" +================ +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 + +""" + +import numpy as np +from matplotlib import pyplot as plt + +from skimage import data +from skimage.feature import corner_harris, corner_subpix, peak_local_max +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 = peak_local_max(corner_harris(image), min_distance=5) +coords_subpix = corner_subpix(image, coords, window_size=13) + +plt.gray() +plt.imshow(image, interpolation='nearest') +plt.plot(coords[:, 1], coords[:, 0], '.b', markersize=3) +plt.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15) +plt.axis((0, 350, 350, 0)) +plt.show() diff --git a/doc/examples/plot_harris.py b/doc/examples/plot_harris.py deleted file mode 100644 index 39c1f29e..00000000 --- a/doc/examples/plot_harris.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -=============================================================================== -Harris Corner detector -=============================================================================== - -The Harris corner filter [1]_ detects "interest points" [2]_ using edge -detection in multiple directions. - -.. [1] http://en.wikipedia.org/wiki/Corner_detection -.. [2] http://en.wikipedia.org/wiki/Interest_point_detection -""" -import numpy as np -from matplotlib import pyplot as plt - -from skimage import data, img_as_float -from skimage.feature import harris, peak_local_max - - -def plot_harris_points(image, filtered_coords): - """ plots corners found in image""" - - plt.imshow(image) - y, x = np.transpose(filtered_coords) - plt.plot(x, y, 'b.') - plt.axis('off') - -# display results -plt.figure(figsize=(8, 3)) -im_lena = img_as_float(data.lena()) -im_text = img_as_float(data.text()) - -filtered_coords = peak_local_max(harris(im_lena), min_distance=4) - -plt.axes([0, 0, 0.3, 0.95]) -plot_harris_points(im_lena, filtered_coords) - -filtered_coords = peak_local_max(harris(im_text), min_distance=4) - -plt.axes([0.2, 0, 0.77, 1]) -plot_harris_points(im_text, filtered_coords) - -plt.show()