X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/2e09f5b5e012d70ed2d4341d40fe3a01bda68165..16a9526d24fbdad7bbc544aeae9fd7ba067b3d91:/imago_pack/hough.py diff --git a/imago_pack/hough.py b/imago_pack/hough.py index deeb9d8..3a3a755 100644 --- a/imago_pack/hough.py +++ b/imago_pack/hough.py @@ -9,24 +9,26 @@ import pcf class Hough: """Hough transform. - This class stores the transformed image and metainformation. + This class stores the parameters of the transformation. """ - def __init__(self, size, dt, init_angle, image): + 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): - """Create Hough transform of the *image* with default parameters.""" - # TODO rename to transform? + 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, @@ -35,14 +37,15 @@ class Hough: def lines_from_list(self, p_list): """Take a list of transformed points and return a list of corresponding lines as (angle, distance) tuples.""" + # TODO! why is distance allways integer? lines = [] for p in p_list: lines.append(self.angle_distance(p)) return lines - def all_lines_h(self): + def all_lines_h(self, image): # TODO what is this? - im_l = self.image.load() + im_l = image.load() lines1 = [] for x in xrange(self.size[0] / 2): for y in xrange(self.size[1]):