X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/cb5eb5a01ee68e22c9ac02a6feaf52c46bfc6c0e..e3b0b7b8f5accc4f6af935923e6db9b34a40b362:/hough.py?ds=sidebyside diff --git a/hough.py b/hough.py index d01416a..0e9fe2d 100644 --- a/hough.py +++ b/hough.py @@ -2,8 +2,6 @@ from math import sin, cos, pi from PIL import Image -from commons import clear - class Hough: def __init__(self, size): self.size = size @@ -20,8 +18,6 @@ class Hough: initial_angle = self.initial_angle for x in xrange(size[0]): - clear() - print "hough transform: {0:>3}/{1}".format(x + 1, size[0]) for y in xrange(size[1]): if image_l[x, y]: # for every angle: @@ -34,7 +30,7 @@ class Hough: size[0] / 2) # column of the matrix closest to the distance column = int(round(distance)) - if column >= 0 and column < size[0]: + if 0 <= column < size[0]: matrix[column][a] += 1 new_image = Image.new('L', size) @@ -50,6 +46,26 @@ class Hough: return new_image + def lines_from_list(self, p_list): + lines = [] + for p in p_list: + lines.append(self.angle_distance(p)) + return lines + + def all_lines_h(self, image): + im_l = image.load() + lines1 = [] + for x in xrange(image.size[0] / 2): + for y in xrange(image.size[1]): + if im_l[x, y]: + lines1.append(self.angle_distance((x, y))) + lines2 = [] + for x in xrange(image.size[0] / 2, image.size[0]): + for y in xrange(image.size[1]): + if im_l[x, y]: + lines2.append(self.angle_distance((x, y))) + return [lines1, lines2] + def all_lines(self, image): im_l = image.load() lines = [] @@ -59,35 +75,6 @@ class Hough: lines.append(self.angle_distance((x, y))) return lines - def find_angle_distance(self, image): - image_l = image.load() - - points = [] - - count = 0 - point_x = 0 - point_y = 0 - for x in xrange(image.size[0] / 2): - for y in xrange(image.size[1] / 2, image.size[1]): - if image_l[x, y]: - count += 1 - point_x += x - point_y += y - points.append((float(point_x) / count, float(point_y) / count)) - - count = 0 - point_x = 0 - point_y = 0 - for x in xrange(image.size[0] / 2, image.size[0]): - for y in xrange(image.size[1] / 2, image.size[1]): - if image_l[x, y]: - count += 1 - point_x += x - point_y += y - points.append((float(point_x) / count, float(point_y) / count)) - - 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)