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()
This commit is contained in:
skidzo 2015-08-25 15:48:26 +02:00
parent 926a08cdb3
commit 31688c76b6

View File

@ -16,7 +16,7 @@
# #
import functools import functools
from PIL import _imaging as core
class Filter(object): class Filter(object):
pass pass
@ -157,7 +157,8 @@ class GaussianBlur(Filter):
class UnsharpMask(Filter): class UnsharpMask(Filter):
"""Unsharp mask filter. """
Unsharp mask filter.
See Wikipedia's entry on `digital unsharp masking`_ for an explanation of See Wikipedia's entry on `digital unsharp masking`_ for an explanation of
the parameters. the parameters.
@ -180,6 +181,22 @@ class UnsharpMask(Filter):
def filter(self, image): def filter(self, image):
return image.unsharp_mask(self.radius, self.percent, self.threshold) 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): class BLUR(BuiltinFilter):
name = "Blur" name = "Blur"
@ -273,3 +290,19 @@ class SHARPEN(BuiltinFilter):
-2, 32, -2, -2, 32, -2,
-2, -2, -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
)