# MAT 201A Winter 2016
# HW 3
# Lu Liu
%pylab inline
from __future__ import print_function
from __future__ import division
from scipy.io import wavfile
%matplotlib inline
Populating the interactive namespace from numpy and matplotlib
img1 = imread('baw.png')
imshow(img1)
<matplotlib.image.AxesImage at 0x1133d9390>
img1.shape
(200, 200, 4)
img1.dtype
dtype('float32')
img1 = sum(img1.astype(float), axis=2)/3.0
imshow(img1)
colorbar()
<matplotlib.colorbar.Colorbar at 0x113838810>
img1.shape
(200, 200)
imshow(img1, cmap=cm.gray)
colorbar()
<matplotlib.colorbar.Colorbar at 0x113c2dc10>
img1 = where(img1 > 0.9, -1, 1) # set the value of white area equals -1, the value of black area equals 1
imshow(img1, cmap='gray')
colorbar()
<matplotlib.colorbar.Colorbar at 0x113e986d0>
from scipy.signal import correlate2d
cc = correlate2d(img1, img1) # auto-correlation
imshow(cc)
colorbar()
<matplotlib.colorbar.Colorbar at 0x114da7b50>
cc.shape
(399, 399)
from scipy.ndimage.filters import maximum_filter
imshow(maximum_filter(cc, (10,10)))
colorbar()
<matplotlib.colorbar.Colorbar at 0x115c583d0>
# I choose a checkerboard picture. And I set 1 value for the black area, -1 value for the white area.
# In the final result, the center of the Matrix is dard red, which means the value overlapped most.
# But at the same time, there are some negative value (showed as blue) distrubuted evenly. The reason of this feature
# because auto-correlation canceled out some negative values and positive values.