bfa4c7a5be567a88cddcdabae3265ad4aa3bf1ed
[imago.git] / imago.py
1 #!/usr/bin/env python
2 """Usage: imago.py file"""
3
4 import sys
5 import Image
6 import im_debug
7 import filter
8 import hough
9
10 class UsageError(Exception):
11     def __init__(self, msg):
12         self.msg = msg
13
14 def main(*argv):
15     """Main function of the program."""
16     try:
17         if argv is ():
18             argv = sys.argv[1:]
19             if argv == []:
20                 raise UsageError('Missing filename')
21         if "--help" in argv:
22                 print __doc__
23                 return 0    
24     except UsageError, err:
25         print >>sys.stderr, err.msg, "(\"imago.py --help\" for help)"
26         return 2
27
28     #TODO exception on file error
29     image = Image.open(argv[0])
30     #im_debug.show(image, "original image")
31
32     im_l = image.convert('L')
33     #im_debug.show(im_l, "ITU-R 601-2 luma transform")
34
35     im_edges = filter.edge_detection(im_l)
36     #im_debug.show(im_edges, "edge detection")
37
38     im_h = filter.high_pass(im_edges, 80)
39     #im_debug.show(im_h, "high pass filter")
40
41     im_hough = hough.transform(im_h)
42     #im_debug.show(im_hough, "hough transform")
43
44     im_h2 = filter.high_pass(im_hough, 120)
45     im_debug.show(im_h2, "high pass filter")
46
47     return 0
48
49 if __name__ == '__main__':
50     sys.exit(main())