scalable edge-detection
authorTomas Musil <tomik.musil@gmail.com>
Sat, 25 Aug 2012 19:23:25 +0000 (21:23 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Sat, 25 Aug 2012 19:23:25 +0000 (21:23 +0200)
filters.py
imago.py
tests/play

index c2648ea..ce955a4 100644 (file)
@@ -1,17 +1,17 @@
 from PIL import Image
 
-def edge_detection(image):
+def edge_detection(image, size):
     image_l = image.load()
     new_image = Image.new('L', image.size)
     new_image_l = new_image.load()
     
-    for x in xrange(2, image.size[0] - 2):
-        for y in xrange(2, image.size[1] - 2):
+    for x in xrange(size, image.size[0] - size):
+        for y in xrange(size, image.size[1] - size):
             pix = (sum([sum([
                 image_l[a, b] 
-                    for b in range(y - 2, y + 3)]) 
-                    for a in range(x - 2, x + 3)])
-                - (25 * image_l[x, y]))
+                    for b in range(y - size, y + size + 1)]) 
+                    for a in range(x - size, x + size + 1)])
+                - (((2 * size + 1) ** 2)  * image_l[x, y]))
             if pix > 255:
                 pix = 255
             if pix < 0:
index 87eaecf..ff49826 100755 (executable)
--- a/imago.py
+++ b/imago.py
@@ -69,7 +69,7 @@ def main():
     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")
 
index 6f65444..25c26fa 100755 (executable)
@@ -2,7 +2,7 @@
 
 clear
 
-for file in $1/*.txt ; do
+for file in "$1/"*".txt" ; do
        echo $file
        cat $file
        sleep 1