X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/3790db9ab7a4871faf0b445c8283c7f0b7b30a22..ca969217d6512b175f6a63d36e3ac34c0e610d2f:/imago_pack/linef.py diff --git a/imago_pack/linef.py b/imago_pack/linef.py index eda82ce..b098257 100644 --- a/imago_pack/linef.py +++ b/imago_pack/linef.py @@ -1,4 +1,4 @@ -"""Go image recognition lines-finding module""" +"""Lines finding module.""" from functools import partial import sys @@ -13,21 +13,14 @@ except ImportError, msg: import filters from hough import Hough -def find_lines(image, show_all, do_something, verbose): - - if verbose: - print >> sys.stderr, "preprocessing" - - if show_all: - do_something(image, "original image") - +def prepare(image, show_all, do_something, verbose): + # TODO comment im_l = image.convert('L') if show_all: do_something(im_l, "ITU-R 601-2 luma transform") if verbose: print >> sys.stderr, "edge detection" - im_edges = filters.edge_detection(im_l) if show_all: do_something(im_edges, "edge detection") @@ -35,7 +28,22 @@ def find_lines(image, show_all, do_something, verbose): im_h = filters.high_pass(im_edges, 100) if show_all: do_something(im_h, "high pass filters") - + + return im_h + + +def find_lines(image, show_all, do_something, verbose): + """Find lines in the *image*.""" + # TODO refactor into smaller functions + + if verbose: + print >> sys.stderr, "preprocessing" + + if show_all: + do_something(image, "original image") + + im_h = prepare(image, show_all, do_something, verbose) + if verbose: print >> sys.stderr, "hough transform" @@ -112,6 +120,7 @@ def find_lines(image, show_all, do_something, verbose): return lines, lines_m[0][0], lines_m[1][0], bounds, im_hough def combine(image1, image2): + """Return a list of points that are present in both images.""" im_l1 = image1.load() im_l2 = image2.load() @@ -124,6 +133,8 @@ def combine(image1, image2): return on_both def line_from_angl_dist((angle, distance), size): + """Take *angle* and *distance* (from the center of the image) of a line and + size of the image. Return the line represented by two points.""" if pi / 4 < angle < 3 * pi / 4: y1 = - size[1] / 2 x1 = int(round((y1 * cos(angle) + distance) / sin(angle))) + size[0] / 2