This is one of the 100 recipes of the IPython Cookbook, the definitive guide to high-performance scientific computing and data science in Python.
You need to download the Child dataset on the book's website. (http://ipython-books.github.io)
import numpy as np
import matplotlib.pyplot as plt
import skimage
import skimage.feature as sf
import matplotlib as mpl
%matplotlib inline
def show(img, cmap=None):
cmap = cmap or plt.cm.gray
plt.figure(figsize=(4,2));
plt.imshow(img, cmap=cmap);
plt.axis('off');
img = plt.imread('data/pic2.jpg')
show(img)
corner_harris
function (we will explain this measure in How it works...).corners = sf.corner_harris(img[:,:,0])
show(corners)
We see that the patterns in the child's coat are particularly well detected by this algorithm.
corner_peaks
function.peaks = sf.corner_peaks(corners)
show(img)
plt.plot(peaks[:,1], peaks[:,0], 'or', ms=4);
ymin, xmin = peaks.min(axis=0)
ymax, xmax = peaks.max(axis=0)
w, h = xmax-xmin, ymax-ymin
k = .25
xmin -= k*w
xmax += k*w
ymin -= k*h
ymax += k*h
show(img[ymin:ymax,xmin:xmax])
You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).
IPython Cookbook, by Cyrille Rossant, Packt Publishing, 2014 (500 pages).