2 from math import sin, cos, pi
3 from commons import clear
11 initial_angle = (pi / 4) + (dt / 2)
13 matrix = [[0]*size[1] for _ in xrange(size[0])]
15 for x in xrange(size[0]):
17 print "hough transform: {0}/{1}".format(x + 1, size[0])
18 for y in xrange(size[1]):
21 for a in xrange(size[1]):
23 # distance is the dot product of vector (x, y) - centerpoint
24 # and a unit vector orthogonal to the angle
25 distance = (((x - (size[0] / 2)) * sin((dt * a) + initial_angle)) +
26 ((y - (size[1] / 2)) * -cos((dt * a) + initial_angle)) +
28 column = int(round(distance)) # column of the matrix closest to the distance
29 if column >= 0 and column < size[0]:
30 matrix[column][a] += 1
32 new_image = Image.new('L', size)
33 new_image_l = new_image.load()
35 minimum = min([min(m) for m in matrix])
37 maximum = max([max(m) for m in matrix]) - minimum
39 for y in xrange(size[1]):
40 for x in xrange(size[0]):
41 new_image_l[x, y] = (float(matrix[x][y] - minimum) / maximum) * 255