X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/fd9a681b1e6fb94684bbfacea2b933ecae1c68ed..4a1012ea76dc2bd7f2920d1901919edc4acc6645:/imago_pack/linef.py diff --git a/imago_pack/linef.py b/imago_pack/linef.py index fb83db4..ccf209e 100644 --- a/imago_pack/linef.py +++ b/imago_pack/linef.py @@ -13,13 +13,12 @@ except ImportError, msg: import filters from hough import Hough -def prepare(image, show_image, verbose): +def prepare(image, show_image, logger): # TODO comment im_l = image.convert('L') show_image(im_l, "ITU-R 601-2 luma transform") - if verbose: - print >> sys.stderr, "edge detection" + logger("edge detection") im_edges = filters.edge_detection(im_l) show_image(im_edges, "edge detection") @@ -34,45 +33,32 @@ def transform(image, hough, show_image): show_image(im_hough, "hough transform") # im_hough.image = filters.peaks(im_hough.image) - # if show_all: - # do_something(im_hough.image, "peak extraction") + # show_image(im_hough.image, "peak extraction") im_h2 = filters.high_pass(im_hough, 96) show_image(im_h2, "second high pass filters") - im_h2 = filters.components2(im_h2) + im_h2 = filters.components(im_h2, 2) show_image(im_h2, "components centers") return im_h2 -def find_lines(image, show_all, do_something, verbose): +def find_lines(image, show_image, logger): """Find lines in the *image*.""" # TODO refactor into smaller functions - - def nothing(a, b): - pass - - if show_all: - show_image = do_something - else: - show_image = nothing - - if verbose: - print >> sys.stderr, "preprocessing" - + + logger("preprocessing") show_image(image, "original image") - im_h = prepare(image, show_image, verbose) + im_h = prepare(image, show_image, logger) hough = Hough.default(im_h) - if verbose: - print >> sys.stderr, "hough transform" + logger("hough transform") im_h2 = transform(im_h, hough, show_image) - if verbose: - print >> sys.stderr, "second hough transform" + logger("second hough transform") # im_hough might be used instead im_h2, but at the moment it brings a lot of # noise to the second transform, which later confuses the center-finding @@ -84,11 +70,10 @@ def find_lines(image, show_all, do_something, verbose): im_h3 = filters.high_pass(im_hough2, 120) show_image(im_h3, "third high pass filter") - im_h3 = filters.components(im_h3) + im_h3 = filters.components(im_h3, 1) show_image(im_h3, "half centers") - if verbose: - print >> sys.stderr, "finding the grid" + logger("finding the lines") lines_m = hough2.all_lines_h(im_h3) lines = []