mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
MultibandFilter
This commit is contained in:
parent
ad4b42f5f4
commit
98ee46827c
|
@ -1105,6 +1105,8 @@ class Image(object):
|
||||||
:param filter: Filter kernel.
|
:param filter: Filter kernel.
|
||||||
:returns: An :py:class:`~PIL.Image.Image` object. """
|
:returns: An :py:class:`~PIL.Image.Image` object. """
|
||||||
|
|
||||||
|
from . import ImageFilter
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
if isinstance(filter, collections.Callable):
|
if isinstance(filter, collections.Callable):
|
||||||
|
@ -1113,11 +1115,10 @@ class Image(object):
|
||||||
raise TypeError("filter argument should be ImageFilter.Filter " +
|
raise TypeError("filter argument should be ImageFilter.Filter " +
|
||||||
"instance or class")
|
"instance or class")
|
||||||
|
|
||||||
multiband = getattr(filter, 'is_multiband', False)
|
multiband = isinstance(filter, ImageFilter.MultibandFilter)
|
||||||
|
|
||||||
if self.im.bands == 1 or multiband:
|
if self.im.bands == 1 or multiband:
|
||||||
return self._new(filter.filter(self.im))
|
return self._new(filter.filter(self.im))
|
||||||
# fix to handle multiband images since _imaging doesn't
|
|
||||||
ims = []
|
ims = []
|
||||||
for c in range(self.im.bands):
|
for c in range(self.im.bands):
|
||||||
ims.append(self._new(filter.filter(self.im.getband(c))))
|
ims.append(self._new(filter.filter(self.im.getband(c))))
|
||||||
|
|
|
@ -22,7 +22,11 @@ class Filter(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Kernel(Filter):
|
class MultibandFilter(Filter):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Kernel(MultibandFilter):
|
||||||
"""
|
"""
|
||||||
Create a convolution kernel. The current version only
|
Create a convolution kernel. The current version only
|
||||||
supports 3x3 and 5x5 integer and floating point kernels.
|
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,
|
:param offset: Offset. If given, this value is added to the result,
|
||||||
after it has been divided by the scale factor.
|
after it has been divided by the scale factor.
|
||||||
"""
|
"""
|
||||||
is_multiband = True
|
|
||||||
|
|
||||||
def __init__(self, size, kernel, scale=None, offset=0):
|
def __init__(self, size, kernel, scale=None, offset=0):
|
||||||
if scale is None:
|
if scale is None:
|
||||||
|
@ -143,13 +146,12 @@ class ModeFilter(Filter):
|
||||||
return image.modefilter(self.size)
|
return image.modefilter(self.size)
|
||||||
|
|
||||||
|
|
||||||
class GaussianBlur(Filter):
|
class GaussianBlur(MultibandFilter):
|
||||||
"""Gaussian blur filter.
|
"""Gaussian blur filter.
|
||||||
|
|
||||||
:param radius: Blur radius.
|
:param radius: Blur radius.
|
||||||
"""
|
"""
|
||||||
name = "GaussianBlur"
|
name = "GaussianBlur"
|
||||||
is_multiband = True
|
|
||||||
|
|
||||||
def __init__(self, radius=2):
|
def __init__(self, radius=2):
|
||||||
self.radius = radius
|
self.radius = radius
|
||||||
|
@ -158,7 +160,7 @@ class GaussianBlur(Filter):
|
||||||
return image.gaussian_blur(self.radius)
|
return image.gaussian_blur(self.radius)
|
||||||
|
|
||||||
|
|
||||||
class UnsharpMask(Filter):
|
class UnsharpMask(MultibandFilter):
|
||||||
"""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
|
||||||
|
@ -173,7 +175,6 @@ class UnsharpMask(Filter):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
name = "UnsharpMask"
|
name = "UnsharpMask"
|
||||||
is_multiband = True
|
|
||||||
|
|
||||||
def __init__(self, radius=2, percent=150, threshold=3):
|
def __init__(self, radius=2, percent=150, threshold=3):
|
||||||
self.radius = radius
|
self.radius = radius
|
||||||
|
|
Loading…
Reference in New Issue
Block a user