X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/438a5577c31f4ab99d4d156417f5484fb9b9ad54..ad06aed1192f4b21ae009c593e8bf2ca5ed14fad:/filters.py?ds=inline diff --git a/filters.py b/filters.py index ce955a4..825834f 100644 --- 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() - 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] - 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: