Commit 072ae88c authored by Taddeüs Kroes's avatar Taddeüs Kroes

ImProc: Added assignment 3.

parent 270d3cbb
from pylab import zeros, imread
def col2bin(color):
return tuple(map(lambda x: round(x - 1), color))
def domainIterator(image):
for x in xrange(image.shape[0]):
for y in xrange(image.shape[1]):
yield x, y
def colHist(image, bins, model):
h = zeros(bins)
image *= bins
if model == 'rgb':
image /= 255
elif model == 'rgba':
pass
for p in domainIterator(image):
h[col2bin(image[p])] += 1
return h
def histogramIntersect(h1, h2):
if h1.shape != h2.shape:
raise ValueError('Shape mismatch between h1 and h2.')
match = 0
for r in xrange(h1.shape[0]):
for g in xrange(h1.shape[1]):
for b in xrange(h1.shape[2]):
match += min(h1[r, g, b], h2[r, g, b])
return match / h2.sum()
# Create table of intersections
bins = [8] * 3
db = map(lambda x: imread('database/%d.jpg' % x), range(1, 21))
table = zeros((len(db), len(db)))
enum = enumerate(db)
for i, im1 in enum:
for j, im2 in enum:
table[i, j] = histogramIntersect(colHist(im1, bins, 'rgb'),
colHist(im2, bins, 'rgb'))
print table
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment