specification version 3
[imago.git] / imago.py
index cf04f53..ff49826 100755 (executable)
--- a/imago.py
+++ b/imago.py
@@ -69,7 +69,7 @@ def main():
     if verbose:
         print >> sys.stderr, "edge detection"
 
     if verbose:
         print >> sys.stderr, "edge detection"
 
-    im_edges = filters.edge_detection(im_l)
+    im_edges = filters.edge_detection(im_l, 2)
     if show_all:    
         do_something(im_edges, "edge detection")
 
     if show_all:    
         do_something(im_edges, "edge detection")
 
@@ -93,7 +93,7 @@ def main():
     if show_all:
         do_something(im_h2, "second high pass filters")
 
     if show_all:
         do_something(im_h2, "second high pass filters")
 
-    im_h2 = filters.components(im_h2)
+    im_h2 = filters.components2(im_h2)
     if show_all:
         do_something(im_h2, "components centers")
 
     if show_all:
         do_something(im_h2, "components centers")
 
@@ -129,8 +129,8 @@ def main():
         draw = ImageDraw.Draw(im_line)
         line_points = set()
         for line in line_l:
         draw = ImageDraw.Draw(im_line)
         line_points = set()
         for line in line_l:
-            draw.line(line_from_angl_dist(line, im_h2.size), fill=255, width=5)
-            draw_c.line(line_from_angl_dist(line, im_c.size), fill=(70, 70, 70), width=5)
+            draw.line(line_from_angl_dist(line, im_h2.size), fill=255, width=7)
+            draw_c.line(line_from_angl_dist(line, im_c.size), fill=(70, 70, 70), width=7)
             for p in combine(im_h2, im_line):
                 line_points.add(p)
         for point in line_points:
             for p in combine(im_h2, im_line):
                 line_points.add(p)
         for point in line_points:
@@ -167,7 +167,10 @@ def stone_color(image, (x, y)):
     suma = 0.
     for i in range(-2, 3):
         for j in range(-2, 3):
     suma = 0.
     for i in range(-2, 3):
         for j in range(-2, 3):
-            suma += sum(image.getpixel((x + i, y + j)))
+            try:
+                suma += sum(image.getpixel((x + i, y + j)))
+            except IndexError:
+                pass
     suma /= 3 * 25
     if suma < 55:
         return 'B'
     suma /= 3 * 25
     if suma < 55:
         return 'B'
@@ -212,7 +215,9 @@ def intersections_from_angl_dist(lines, size):
             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 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))
-                line.append((int(x + size[0] / 2), int(y + size[1] / 2)))
+                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
 
         intersections.append(line)
     return intersections