X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/8d05ccd11445ae069ae14dfb95d566907546e989..cb5eb5a01ee68e22c9ac02a6feaf52c46bfc6c0e:/hough.py?ds=inline diff --git a/hough.py b/hough.py index 5fca93f..d01416a 100644 --- a/hough.py +++ b/hough.py @@ -1,10 +1,12 @@ -from PIL import Image from math import sin, cos, pi + +from PIL import Image + from commons import clear class Hough: def __init__(self, size): - self.size = size + self.size = size self.dt = pi / size[1] self.initial_angle = (pi / 4) + (self.dt / 2) @@ -30,7 +32,8 @@ class Hough: distance = (((x - (size[0] / 2)) * sin((dt * a) + initial_angle)) + ((y - (size[1] / 2)) * -cos((dt * a) + initial_angle)) + size[0] / 2) - column = int(round(distance)) # column of the matrix closest to the distance + # column of the matrix closest to the distance + column = int(round(distance)) if column >= 0 and column < size[0]: matrix[column][a] += 1 @@ -48,12 +51,12 @@ class Hough: return new_image def all_lines(self, image): - im_l = image.load() - lines = [] - for x in xrange(image.size[0]): + im_l = image.load() + lines = [] + for x in xrange(image.size[0]): for y in xrange(image.size[1]): - if im_l[x, y]: - lines.append(self.angle_distance((x, y))) + if im_l[x, y]: + lines.append(self.angle_distance((x, y))) return lines def find_angle_distance(self, image): @@ -86,5 +89,5 @@ class Hough: return [self.angle_distance(p) for p in points] def angle_distance(self, point): - return (self.dt * point[1] + self.initial_angle, point[0] - self.size[0] / 2) - + return (self.dt * point[1] + self.initial_angle, point[0] - self.size[0] / 2) +