we are going to compare two images from a children book using 2d correlation. these images are there to find diffrences so they are basically the same with minor change. then we are going to find a feature in the image.
%pylab inline
rcParams['figure.figsize'] = (10, 4) #wide graphs by default
from __future__ import print_function
from __future__ import division
Populating the interactive namespace from numpy and matplotlib
im1 = imread('dif1.jpg')
im2 = imread('dif2.jpg')
imshow(im1)
<matplotlib.image.AxesImage at 0x10d94a4a8>
imshow(im2)
<matplotlib.image.AxesImage at 0x10eace400>
im1 = sum(im1.astype(float), axis=2)/4.0
im2 = sum(im2.astype(float), axis=2)/4.0
imshow(im1)
colorbar()
<matplotlib.colorbar.Colorbar at 0x10db37a90>
im1 = where(im1 > 70, -1, 1)
im2 = where(im2 > 70, -1, 1)
imshow(im1, cmap='gray')
<matplotlib.image.AxesImage at 0x108a48198>
imshow(im2, cmap='gray')
<matplotlib.image.AxesImage at 0x10d5af048>
from scipy.signal import correlate2d
cc = correlate2d(im1,im2)
imshow(cc)
colorbar()
gcf().set_figheight(8)
clock = imread('clock.jpg')
imshow(clock)
<matplotlib.image.AxesImage at 0x10df40128>
clock = sum(clock.astype(float), axis=2)/4.0
clock = where(clock > 70, -1, 1)
imshow(clock, cmap='gray')
<matplotlib.image.AxesImage at 0x10e44cf98>
cc = correlate2d(im1,clock)
imshow(cc)
colorbar()
gcf().set_figheight(8)