From c8277daa35d45569a356edb7be50d83f73c4e4d1 Mon Sep 17 00:00:00 2001 From: Tomas Musil Date: Mon, 21 Oct 2013 18:09:34 +0200 Subject: [PATCH] fix bug in color conversion --- TODO | 1 + imago_pack/intrsc.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 3c4e5ad..4c022c6 100644 --- a/TODO +++ b/TODO @@ -6,3 +6,4 @@ faster (and more realiable) grid search stone finding better user interface faster image processing +use floats in computations diff --git a/imago_pack/intrsc.py b/imago_pack/intrsc.py index d26bea4..ce89cb2 100644 --- a/imago_pack/intrsc.py +++ b/imago_pack/intrsc.py @@ -108,6 +108,14 @@ def intersections_from_angl_dist(lines, size, get_all=True): intersections.append(line) return intersections +def RGBtoSat(c): + max_diff = max(c) - min(c) + if max_diff == 0: + return 0 + else: + #TODO simplify this + return max_diff / float(255. - abs(max(c) + min(c) - 255)) + def stone_color_raw(image, (x, y)): """Given image and coordinates, return stone color.""" suma = [] @@ -119,8 +127,7 @@ def stone_color_raw(image, (x, y)): 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(max(s) - min(s) / float(255. - abs(max(s) + min(s) - 255)) - for s in suma) / (25. * 255.) + saturation = sum(RGBtoSat(s) 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 -- 2.4.2