Mat 201A Winter Jacob Burrows
%pylab inline
from __future__ import print_function
from __future__ import division
Populating the interactive namespace from numpy and matplotlib
i = imread('score.png')
imshow(i)
<matplotlib.image.AxesImage at 0x24745b30>
i.shape #shape of array
(673, 816, 3)
i = sum(i.astype(float), axis=2)/3.0
imshow(i)
colorbar()
#uses color bar to demonstrate an array of each element
title("Color Arrays")
<matplotlib.text.Text at 0x1fcd5ad0>
i = where(i > 0.65, 1, -1)
imshow(i, cmap='gray')
colorbar()
title("Star Splangeld Banner")
<matplotlib.text.Text at 0x184d7390>
n = imread('star.png')
imshow(n)
#fragment of picture
<matplotlib.image.AxesImage at 0x250f3130>
n = n.astype(float).sum(axis=-1)/3
n = where(n > 0.65, 1, -1) #sets threshhold
imshow(n, cmap=cm.gray, interpolation='nearest')
<matplotlib.image.AxesImage at 0x253b2410>
from scipy.signal import correlate2d
cc = correlate2d(i, n)
imshow(cc)
colorbar()
gcf().set_figheight(8)
#changes value
imshow(where(cc > 1000, 1, 0), interpolation='nearest', cmap=cm.gray)
colorbar()
gcf().set_figheight(8)
title("Location of Star")
#shows where the star position more obviously
<matplotlib.text.Text at 0x280661d0>
from scipy.ndimage.filters import maximum_filter
imshow(maximum_filter(cc, (10,10)))
gcf().set_figheight(8)
subplot(121)
imshow(maximum_filter(cc, (50,50)))
subplot(122)
imshow(i, cmap=cm.gray)
gcf().set_figheight(8)
#compares image with original
mf = maximum_filter(cc, (50,50)) #displays a square to visualize easier than the (10,10)
argmax(mf) #another formant
16888
unravel_index(argmax(mf), mf.shape) #position of most correlated part changed the format from 65
(19, 282)
argmax(cc) #original cross corolation
37888
unravel_index(argmax(cc), cc.shape) #cc is cross corolation
(43, 306)