removed some unused code
[imago.git] / imago.py
index 810aa53..decc7a6 100755 (executable)
--- a/imago.py
+++ b/imago.py
@@ -16,6 +16,7 @@ except ImportError, msg:
 
 import im_debug
 import linef
 
 import im_debug
 import linef
+import manual
 
 def main():
     """Main function of the program."""
 
 def main():
     """Main function of the program."""
@@ -25,6 +26,8 @@ def main():
                         help="image to analyse")
     parser.add_argument('-w', type=int, default=640,
                         help="scale image to the specified width before analysis")
                         help="image to analyse")
     parser.add_argument('-w', type=int, default=640,
                         help="scale image to the specified width before analysis")
+    parser.add_argument('-m', '--manual', dest='manual_mode', action='store_true',
+                        help="manual grid selection")
     parser.add_argument('-d', '--debug', dest='show_all', action='store_true',
                         help="show every step of the computation")
     parser.add_argument('-s', '--save', dest='saving', action='store_true',
     parser.add_argument('-d', '--debug', dest='show_all', action='store_true',
                         help="show every step of the computation")
     parser.add_argument('-s', '--save', dest='saving', action='store_true',
@@ -51,9 +54,23 @@ def main():
     if args.saving:
         do_something = imsave("saved/" + args.file[0][:-4] + "_" +
                                str(image.size[0]) + "/").save
     if args.saving:
         do_something = imsave("saved/" + args.file[0][:-4] + "_" +
                                str(image.size[0]) + "/").save
-    
-    lines = linef.find_lines(image, show_all, do_something, verbose)
 
 
+    if args.manual_mode:
+        try:
+            lines = manual.find_lines(image)
+        except manual.UserQuitError:
+            #TODO ask user to try again
+            return 1
+    else:
+        lines = linef.find_lines(image, show_all, do_something, verbose)
+
+    image_g = image.copy()
+    draw = ImageDraw.Draw(image_g)
+    for line in [l for s in lines for l in s]:
+        draw.line(linef.line_from_angl_dist(line, image.size), fill=(120, 255, 120))
+    if show_all:
+        do_something(image_g, "the grid")
     intersections = intersections_from_angl_dist(lines, image.size)
     image_g = image.copy()
     draw = ImageDraw.Draw(image_g)
     intersections = intersections_from_angl_dist(lines, image.size)
     image_g = image.copy()
     draw = ImageDraw.Draw(image_g)
@@ -98,18 +115,6 @@ class imsave():
         image.save(filename, 'JPEG')
         self.saving_num += 1
 
         image.save(filename, 'JPEG')
         self.saving_num += 1
 
-def combine(image1, image2):
-    im_l1 = image1.load()
-    im_l2 = image2.load()
-
-    on_both = []
-
-    for x in xrange(image1.size[0]):
-        for y in xrange(image1.size[1]):
-            if im_l1[x, y] and im_l2[x, y]:
-                on_both.append((x, y))
-    return on_both
-
 def intersections_from_angl_dist(lines, size):
     intersections = []
     for (angl1, dist1) in sorted(lines[1], key=itemgetter(1)):
 def intersections_from_angl_dist(lines, size):
     intersections = []
     for (angl1, dist1) in sorted(lines[1], key=itemgetter(1)):