X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/6d19451cd1ebad960d015a79f27ab95f86c31d61..71f8dfb76a3534132d68e3f65af7535e723cc44b:/imago_pack/hough.py?ds=inline diff --git a/imago_pack/hough.py b/imago_pack/hough.py index 77f30b2..6235b5d 100644 --- a/imago_pack/hough.py +++ b/imago_pack/hough.py @@ -7,33 +7,44 @@ from PIL import Image import pcf class Hough: - def __init__(self, size, dt, init_angle, image): - self.size = size # TODO is this a tuple? This language is crazy - self.dt = dt + """Hough transform. + + This class stores the parameters of the transformation. + """ + def __init__(self, size, dt, init_angle): + self.size = size # this is a tuple (width, height) + self.dt = dt # this is the angle step in hough transform self.initial_angle = init_angle - self.image = image @classmethod - def Transform(cls, image): + def default(cls, image): + """Default parameters for Hough transform of the *image*.""" size = image.size dt = pi / size[1] initial_angle = (pi / 4) + (dt / 2) - image_s = pcf.hough(size, image.tostring(), initial_angle, dt) - image_t = Image.fromstring('L', size, image_s) - return cls(size, dt, initial_angle, image_t) + return cls(size, dt, initial_angle) + + def transform(self, image): + image_s = pcf.hough(self.size, image.tostring(), self.initial_angle, + self.dt) + image_t = Image.fromstring('L', self.size, image_s) + return image_t def apply_filter(self, filter_f): return Hough(self.size, self.dt, self.initial_angle, filter_f(self.image)) def lines_from_list(self, p_list): + """Take a list of transformed points and return a list of corresponding + lines as (angle, distance) tuples.""" lines = [] for p in p_list: lines.append(self.angle_distance(p)) return lines - def all_lines_h(self): - im_l = self.image.load() + def all_lines_h(self, image): + # TODO what is this? + im_l = image.load() lines1 = [] for x in xrange(self.size[0] / 2): for y in xrange(self.size[1]): @@ -47,6 +58,7 @@ class Hough: return [lines1, lines2] def all_lines(self): + # TODO what is this? how does it differ from the upper one? im_l = self.image.load() lines = [] for x in xrange(self.size[0]): @@ -56,6 +68,8 @@ class Hough: return lines def angle_distance(self, point): + """Take a point from the transformed image and return the corresponding + line in the original as (angle, distance) tuple.""" return (self.dt * point[1] + self.initial_angle, point[0] - self.size[0] / 2)