X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/a5500034cf027ff6fec0d1dc236b36d3b1d82778..6d19451cd1ebad960d015a79f27ab95f86c31d61:/imago_pack/intrsc.py diff --git a/imago_pack/intrsc.py b/imago_pack/intrsc.py index 04ef350..c64386f 100644 --- a/imago_pack/intrsc.py +++ b/imago_pack/intrsc.py @@ -5,6 +5,7 @@ from operator import itemgetter import ImageDraw +import filters import k_means import output @@ -36,10 +37,14 @@ def board(image, lines, show_all, do_something): draw.point((x , y), fill=(120, 255, 120)) do_something(image_g, "intersections") + image_c = filters.color_enhance(image) + if show_all: + do_something(image_c, "white balance") + board_raw = [] for line in intersections: - board_raw.append([stone_color_raw(image, intersection) for intersection in + board_raw.append([stone_color_raw(image_c, intersection) for intersection in line]) board_raw = sum(board_raw, []) @@ -59,7 +64,7 @@ def board(image, lines, show_all, do_something): pyplot.show() clusters = k_means.cluster(3, 2,zip(zip(luma, saturation), range(len(luma))), - [[0., 0.], [0.5, 0.5], [1., 0.]]) + [[0., 0.5], [0.5, 0.5], [1., 0.5]]) #clusters.sort(key=mean_luma) if show_all: @@ -124,16 +129,19 @@ def RGBtoSat(c): def stone_color_raw(image, (x, y)): """Given image and coordinates, return stone color.""" + size = 3 suma = [] - for i in range(-2, 3): - for j in range(-2, 3): + t = 0 + for i in range(-size, size + 1): + for j in range(-size, size + 1): try: suma.append(image.getpixel((x + i, y + j))) + t += 1 except IndexError: pass - luma = sum([0.30 * sum(s[0] for s in suma) / 25., 0.59 * sum(s[1] for s in suma) / 25., - 0.11 * sum(s[2] for s in suma) / 25.]) / 255. - saturation = sum(RGBtoSat(s) for s in suma) / 25. - color = [sum(s[0] for s in suma) / 25., sum(s[1] for s in suma) / 25., - sum(s[2] for s in suma) / 25.] + luma = sum([0.30 * sum(s[0] for s in suma) / t, 0.59 * sum(s[1] for s in suma) / t, + 0.11 * sum(s[2] for s in suma) / t]) / 255. + saturation = sum(RGBtoSat(s) for s in suma) / t + color = [sum(s[0] for s in suma) / t, sum(s[1] for s in suma) / t, + sum(s[2] for s in suma) / t] return luma, saturation, color