This is one of the 100 recipes of the IPython Cookbook, the definitive guide to high-performance scientific computing and data science in Python.

# 11.4. Finding points of interest in an image¶

You need to download the Child dataset on the book's website. (http://ipython-books.github.io)

1. Let's import the packages.
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
import skimage
import skimage.feature as sf
import matplotlib as mpl
%matplotlib inline

1. We create a function to display a colored or grayscale image.
In [ ]:
def show(img, cmap=None):
cmap = cmap or plt.cm.gray
plt.figure(figsize=(4,2));
plt.imshow(img, cmap=cmap);
plt.axis('off');

In [ ]:
img = plt.imread('data/pic2.jpg')

In [ ]:
show(img)

1. We find salient points in the image with the Harris corner method. The first step consists in computing the Harris corner measure response image with the corner_harris function (we will explain this measure in How it works...).
In [ ]:
corners = sf.corner_harris(img[:,:,0])

In [ ]:
show(corners)


We see that the patterns in the child's coat are particularly well detected by this algorithm.

1. The next step consists in detecting corners from this measure image, using the corner_peaks function.
In [ ]:
peaks = sf.corner_peaks(corners)

In [ ]:
show(img)
plt.plot(peaks[:,1], peaks[:,0], 'or', ms=4);

1. Finally, we create a box around the corner points to define our region of interest.
In [ ]:
ymin, xmin = peaks.min(axis=0)
ymax, xmax = peaks.max(axis=0)
w, h = xmax-xmin, ymax-ymin

In [ ]:
k = .25
xmin -= k*w
xmax += k*w
ymin -= k*h
ymax += k*h

In [ ]:
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).