-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(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 - 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:
- pix = 0
- new_image_l[x, y] = pix
- return new_image
+import pcf
+
+def edge_detection(image):
+ image = image.filter(ImageFilter.GaussianBlur())
+ # GaussianBlur is undocumented class, it might not work in future versions
+ # of PIL
+ image = Image.fromstring('L', image.size, pcf.edge(image.size, image.tostring()))
+ return image