Commit 8f8ed460 authored by Richard Torenvliet's avatar Richard Torenvliet

Merge branch 'master' of github.com:taddeus/licenseplates

parents 6dee71df 6de11197
This diff is collapsed.
...@@ -6,12 +6,14 @@ class Histogram: ...@@ -6,12 +6,14 @@ class Histogram:
self.max = max self.max = max
def add(self, number): def add(self, number):
bin_index = self.get_bin_index(number) #bin_index = self.get_bin_index(number)
self.bins[bin_index] += 1 #self.bins[bin_index] += 1
self.bins[number] += 1
def remove(self, number): def remove(self, number):
bin_index = self.get_bin_index(number) #bin_index = self.get_bin_index(number)
self.bins[bin_index] -= 1 #self.bins[bin_index] -= 1
self.bins[number] -= 1
def get_bin_index(self, number): def get_bin_index(self, number):
return (number - self.min) / ((self.max - self.min) / len(self.bins)) return (number - self.min) / ((self.max - self.min) / len(self.bins))
......
from pylab import floor
def pV(image, x, y):
'''Get the value of a point x,y in the given image, where x and y are not
necessary integers, so the value is interpolated from its neighbouring
pixels.'''
if inImage(image, x, y):
x_low = floor(x)
x_high = floor(x + 1)
y_low = floor(y)
y_high = floor(y + 1)
x_y = (x_high - x_low) * (y_high - y_low)
interpolatedValue = image[x_low, y_low] / x_y * (x_high - x) * \
(y_high - y)\
+ image[x_high][y_low] / x_y * (x - x_low) * \
(y_high - y)\
+ image[x_low][y_high] / x_y * (x_high - x) * \
(y - y_low)\
+ image[x_high][y_high] / x_y * (x - x_low) * \
(y - y_low)
return interpolatedValue
else:
constantValue = 0
return constantValue
def inImage(image, x, y):
'''Return if the pixels is within the image bounds.'''
return (x > 0 and x < image.get_height() - 1 \
and y > 0 and y < image.get_width() - 1)
...@@ -102,7 +102,7 @@ i = 0 ...@@ -102,7 +102,7 @@ i = 0
s = ' c\y' s = ' c\y'
for y in Y: for y in Y:
s += '| %f' % y s += ' | %f' % y
s += '\n' s += '\n'
...@@ -110,12 +110,13 @@ for c in C: ...@@ -110,12 +110,13 @@ for c in C:
s += ' %7s' % c s += ' %7s' % c
for y in Y: for y in Y:
s += '| %8d' % int(round(results[i] * 100)) s += ' | %8d' % int(round(results[i] * 100))
i += 1 i += 1
s += '\n' s += '\n'
s += '\nBest result: %.3f%% for C = %f and gamma = %f' % best[:3] s += '\nBest result: %.3f%% for C = %f and gamma = %f' \
% ((best[0] * 100,) + best[1:3])
print 'Saving results...' print 'Saving results...'
f = open(results_file, 'w+') f = open(results_file, 'w+')
......
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