color distribution plot
[imago.git] / intrsc.py
index cefed90..ba36b6d 100644 (file)
--- a/intrsc.py
+++ b/intrsc.py
@@ -34,11 +34,14 @@ def board(image, lines, show_all, do_something):
         do_something(image_g, "intersections")
 
     board_r = []
         do_something(image_g, "intersections")
 
     board_r = []
+    board_raw = []
     
     for line in intersections:
         board_r.append([stone_color(image, intersection) for intersection in
                       line])
     
     for line in intersections:
         board_r.append([stone_color(image, intersection) for intersection in
                       line])
-    return board_r
+        board_raw.append([stone_color_raw(image, intersection) for intersection in
+                      line])
+    return board_r, board_raw
 
 def intersections_from_angl_dist(lines, size, get_all=True):
     """Take grid-lines and size of the image. Return intersections."""
 
 def intersections_from_angl_dist(lines, size, get_all=True):
     """Take grid-lines and size of the image. Return intersections."""
@@ -73,3 +76,16 @@ def stone_color(image, (x, y)):
         return '.'
     else:
         return 'W'
         return '.'
     else:
         return 'W'
+   
+def stone_color_raw(image, (x, y)):
+    """Given image and coordinates, return stone color."""
+    suma = []
+    for i in range(-2, 3):
+        for j in range(-2, 3):
+            try:
+                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