From 98ee46827c00c375d45bcee0aa35cf4d0fc49e4e Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 10 Sep 2017 12:59:51 +0300 Subject: [PATCH] MultibandFilter --- PIL/Image.py | 7 ++++--- PIL/ImageFilter.py | 13 +++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index d3a21a898..58fb7c508 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1105,6 +1105,8 @@ class Image(object): :param filter: Filter kernel. :returns: An :py:class:`~PIL.Image.Image` object. """ + from . import ImageFilter + self.load() if isinstance(filter, collections.Callable): @@ -1113,11 +1115,10 @@ class Image(object): raise TypeError("filter argument should be ImageFilter.Filter " + "instance or class") - multiband = getattr(filter, 'is_multiband', False) - + multiband = isinstance(filter, ImageFilter.MultibandFilter) if self.im.bands == 1 or multiband: return self._new(filter.filter(self.im)) - # fix to handle multiband images since _imaging doesn't + ims = [] for c in range(self.im.bands): ims.append(self._new(filter.filter(self.im.getband(c)))) diff --git a/PIL/ImageFilter.py b/PIL/ImageFilter.py index 77d626ce8..c89225484 100644 --- a/PIL/ImageFilter.py +++ b/PIL/ImageFilter.py @@ -22,7 +22,11 @@ class Filter(object): pass -class Kernel(Filter): +class MultibandFilter(Filter): + pass + + +class Kernel(MultibandFilter): """ Create a convolution kernel. The current version only supports 3x3 and 5x5 integer and floating point kernels. @@ -39,7 +43,6 @@ class Kernel(Filter): :param offset: Offset. If given, this value is added to the result, after it has been divided by the scale factor. """ - is_multiband = True def __init__(self, size, kernel, scale=None, offset=0): if scale is None: @@ -143,13 +146,12 @@ class ModeFilter(Filter): return image.modefilter(self.size) -class GaussianBlur(Filter): +class GaussianBlur(MultibandFilter): """Gaussian blur filter. :param radius: Blur radius. """ name = "GaussianBlur" - is_multiband = True def __init__(self, radius=2): self.radius = radius @@ -158,7 +160,7 @@ class GaussianBlur(Filter): return image.gaussian_blur(self.radius) -class UnsharpMask(Filter): +class UnsharpMask(MultibandFilter): """Unsharp mask filter. See Wikipedia's entry on `digital unsharp masking`_ for an explanation of @@ -173,7 +175,6 @@ class UnsharpMask(Filter): """ name = "UnsharpMask" - is_multiband = True def __init__(self, radius=2, percent=150, threshold=3): self.radius = radius