X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/e3b0b7b8f5accc4f6af935923e6db9b34a40b362..3fa492032fb6f72fc8d153c0d11ad61155e8c1b9:/imago.py?ds=sidebyside diff --git a/imago.py b/imago.py index 81aa1ac..a0eabfd 100755 --- a/imago.py +++ b/imago.py @@ -6,7 +6,6 @@ import sys import os import math import argparse -from operator import itemgetter try: import Image, ImageDraw @@ -17,6 +16,7 @@ except ImportError, msg: import im_debug import linef import manual +import intrsc def main(): """Main function of the program.""" @@ -64,45 +64,14 @@ def main(): else: lines = linef.find_lines(image, show_all, do_something, verbose) - image_g = image.copy() - draw = ImageDraw.Draw(image_g) - for line in [l for s in lines for l in s]: - draw.line(linef.line_from_angl_dist(line, image.size), fill=(120, 255, 120)) - if show_all: - do_something(image_g, "the grid") - - intersections = intersections_from_angl_dist(lines, image.size) - image_g = image.copy() - draw = ImageDraw.Draw(image_g) - for line in intersections: - for (x, y) in line: - draw.point((x , y), fill=(120, 255, 120)) - - for line in intersections: - print ' '.join([stone_color(image, intersection) for intersection in - line]) + board = intrsc.board(image, lines, show_all, do_something) - if show_all: - do_something(image_g, "intersections") + #simple ASCII output: + for line in board: + print ' '.join(line) return 0 -def stone_color(image, (x, y)): - suma = 0. - for i in range(-2, 3): - for j in range(-2, 3): - try: - suma += sum(image.getpixel((x + i, y + j))) - except IndexError: - pass - suma /= 3 * 25 - if suma < 55: - return 'B' - elif suma < 200: - return '.' - else: - return 'W' - class imsave(): def __init__(self, saving_dir): self.saving_dir = saving_dir @@ -115,32 +84,6 @@ class imsave(): image.save(filename, 'JPEG') self.saving_num += 1 -def combine(image1, image2): - im_l1 = image1.load() - im_l2 = image2.load() - - on_both = [] - - for x in xrange(image1.size[0]): - for y in xrange(image1.size[1]): - if im_l1[x, y] and im_l2[x, y]: - on_both.append((x, y)) - return on_both - -def intersections_from_angl_dist(lines, size): - intersections = [] - for (angl1, dist1) in sorted(lines[1], key=itemgetter(1)): - line = [] - for (angl2, dist2) in sorted(lines[0], key=itemgetter(1)): - if abs(angl1 - angl2) > 0.4: - x = - ((dist2 / math.cos(angl2))-(dist1 / math.cos(angl1))) / (math.tan(angl1) - math.tan(angl2)) - y = (math.tan(angl1) * x) - (dist1 / math.cos(angl1)) - if (-size[0] / 2 < x < size[0] / 2 and - -size[1] / 2 < y < size[1] / 2): - line.append((int(x + size[0] / 2), int(y + size[1] / 2))) - intersections.append(line) - return intersections - if __name__ == '__main__': try: sys.exit(main())