X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/f0548db6acfd9616ddafa443e45103fc6655e0e4:/intrsc.py..ecc0929cb0e011db2825e79d7495d7ef7b113e1e:/imago_pack/intrsc.py diff --git a/intrsc.py b/imago_pack/intrsc.py similarity index 82% rename from intrsc.py rename to imago_pack/intrsc.py index 97f9987..445c447 100644 --- a/intrsc.py +++ b/imago_pack/intrsc.py @@ -43,18 +43,18 @@ def board(image, lines, show_all, do_something): board_raw = sum(board_raw, []) ### Show color distribution - luma = [(0.30 * s[0] + 0.59 * s[1] + 0.11 * s[2]) / 255. - for s in board_raw] - saturation = [(max(s) - min(s)) / (255 - abs(max(s) + min(s) - 255)) - for s in board_raw] + luma = [s[0] for s in board_raw] + saturation = [s[1] for s in board_raw] + if show_all: import matplotlib.pyplot as pyplot - pyplot.scatter(luma, saturation, color=[(s[0]/255., s[1]/255., s[2]/255., 1.) - for s in board_raw]) + pyplot.scatter(luma, saturation, + color=[(s[2][0]/255., s[2][1]/255., s[2][2]/255., 1.) + for s in board_raw]) pyplot.show() clusters = k_means.cluster(3, 2,zip(zip(luma, saturation), range(len(luma))), - [[0., 0.], [0.5, 0.25], [1., 0.5]]) + [[0., 0.], [0.5, 0.5], [1., 1.]]) #clusters.sort(key=mean_luma) if show_all: @@ -115,6 +115,10 @@ def stone_color_raw(image, (x, y)): suma.append(image.getpixel((x + i, y + j))) except IndexError: pass - suma = (sum(s[0] for s in suma) / 25., sum(s[1] for s in suma) / 25., - sum(s[2] for s in suma) / 25.) - return suma + 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(max(s) - min(s) / float(255. - abs(max(s) + min(s) - 255)) + for s in suma) / (25. * 255.) + 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.] + return luma, saturation, color