From 31688c76b6886e5714f6242baabb85f33cb56d57 Mon Sep 17 00:00:00 2001 From: skidzo Date: Tue, 25 Aug 2015 15:48:26 +0200 Subject: [PATCH] Update ImageFilter.py added Scobel Filter for higher noise robustness and better edge detection. working on nonlinear filters.... coming soon... ...tested with relatively big Images have not given Memory Errors... use it as follows: im = Image.fromarray(Iarray).convert("RGBA") # or from file.... im3 = ImageFilter.Sobel().filter(im) im3.show() --- PIL/ImageFilter.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/PIL/ImageFilter.py b/PIL/ImageFilter.py index baa168aa7..9a788a5f4 100644 --- a/PIL/ImageFilter.py +++ b/PIL/ImageFilter.py @@ -16,7 +16,7 @@ # import functools - +from PIL import _imaging as core class Filter(object): pass @@ -157,7 +157,8 @@ class GaussianBlur(Filter): class UnsharpMask(Filter): - """Unsharp mask filter. + """ + Unsharp mask filter. See Wikipedia's entry on `digital unsharp masking`_ for an explanation of the parameters. @@ -180,6 +181,22 @@ class UnsharpMask(Filter): def filter(self, image): return image.unsharp_mask(self.radius, self.percent, self.threshold) +class Sobel(Filter): + + """ + Using the Scobeloperator to integrate perpendicular towards the direction of the derivative. + This is good for getting rid of disturbances. + """ + name = "Scobel" + + def __init__(self, size=3): + self.size = size + + def filter(self, image): + im1 = image.filter( SOBEL1 ) + im2 = image.filter( SOBEL2 ) + + return image._new(core.blend(im1.im, im2.im, 0.5)) class BLUR(BuiltinFilter): name = "Blur" @@ -273,3 +290,19 @@ class SHARPEN(BuiltinFilter): -2, 32, -2, -2, -2, -2 ) + +class SOBEL1(BuiltinFilter): + name = "Sobel_1" + filterargs = (3, 3), 1, 255, ( + -1, 0, 1, + -2, 0, 2, + -1, 0, 1 + ) + +class SOBEL2(BuiltinFilter): + name = "Sobel_2" + filterargs = (3, 3), 1, 255, ( + -1, -2, -1, + 0, 0, 0, + 1, 2, 1 + )