projekty
/
imago.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
64f201c
)
better edge detection
author
Tomas Musil
<tomik.musil@gmail.com>
Sat, 22 Sep 2012 11:03:51 +0000
(13:03 +0200)
committer
Tomas Musil
<tomik.musil@gmail.com>
Sat, 22 Sep 2012 11:03:51 +0000
(13:03 +0200)
filters.py
patch
|
blob
|
history
imago.py
patch
|
blob
|
history
diff --git
a/filters.py
b/filters.py
index
ce955a4
..
825834f
100644
(file)
--- a/
filters.py
+++ b/
filters.py
@@
-1,17
+1,20
@@
-from PIL import Image
+from PIL import Image
, ImageFilter
-def edge_detection(image, size):
+def edge_detection(image):
+ image = image.filter(ImageFilter.GaussianBlur())
+ # GaussianBlur is undocumented class, it might not work in future versions
+ # of PIL
image_l = image.load()
new_image = Image.new('L', image.size)
new_image_l = new_image.load()
image_l = image.load()
new_image = Image.new('L', image.size)
new_image_l = new_image.load()
- for x in xrange(
size, image.size[0] - size
):
- for y in xrange(
size, image.size[1] - size
):
+ for x in xrange(
2, image.size[0] - 2
):
+ for y in xrange(
2, image.size[1] - 2
):
pix = (sum([sum([
image_l[a, b]
pix = (sum([sum([
image_l[a, b]
- 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]))
+ for b in range(y -
2, y + 3
)])
+ for a in range(x -
2, x + 3
)])
+ - (
25
* image_l[x, y]))
if pix > 255:
pix = 255
if pix < 0:
if pix > 255:
pix = 255
if pix < 0:
diff --git
a/imago.py
b/imago.py
index
ff49826
..
87eaecf
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
, 2
)
+ im_edges = filters.edge_detection(im_l)
if show_all:
do_something(im_edges, "edge detection")
if show_all:
do_something(im_edges, "edge detection")