mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
ImageFilter.BoxBlur
This commit is contained in:
parent
d5f069472d
commit
6900a7707f
|
@ -160,6 +160,26 @@ class GaussianBlur(MultibandFilter):
|
|||
return image.gaussian_blur(self.radius)
|
||||
|
||||
|
||||
class BoxBlur(MultibandFilter):
|
||||
"""Blurs the image by setting each pixel to the average value of the pixels
|
||||
in a square box extending radius pixels in each direction.
|
||||
Supports float radius of arbitrary size. Uses an optimized implementation
|
||||
which runs in linear time relative to the size of the image
|
||||
for any radius value.
|
||||
|
||||
:param radius: Size of the box in one direction. Radius 0 does not blur,
|
||||
returns an identical image. Radius 1 takes 1 pixel
|
||||
in each direction, i.e. 9 pixels in total.
|
||||
"""
|
||||
name = "BoxBlur"
|
||||
|
||||
def __init__(self, radius):
|
||||
self.radius = radius
|
||||
|
||||
def filter(self, image):
|
||||
return image.box_blur(self.radius)
|
||||
|
||||
|
||||
class UnsharpMask(MultibandFilter):
|
||||
"""Unsharp mask filter.
|
||||
|
||||
|
|
|
@ -13,20 +13,6 @@ sample.putdata(sum([
|
|||
], []))
|
||||
|
||||
|
||||
class ImageMock(object):
|
||||
def __init__(self):
|
||||
self.im = self
|
||||
|
||||
def load(self):
|
||||
pass
|
||||
|
||||
def _new(self, im):
|
||||
return im
|
||||
|
||||
def box_blur(self, radius, n):
|
||||
return radius, n
|
||||
|
||||
|
||||
class TestBoxBlurApi(PillowTestCase):
|
||||
|
||||
def test_imageops_box_blur(self):
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageFilter
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
|
||||
class TestImageFilter(PillowTestCase):
|
||||
|
@ -9,10 +8,11 @@ class TestImageFilter(PillowTestCase):
|
|||
def test_sanity(self):
|
||||
|
||||
def filter(filter):
|
||||
im = hopper("L")
|
||||
out = im.filter(filter)
|
||||
self.assertEqual(out.mode, im.mode)
|
||||
self.assertEqual(out.size, im.size)
|
||||
for mode in ["L", "RGB", "CMYK"]:
|
||||
im = hopper(mode)
|
||||
out = im.filter(filter)
|
||||
self.assertEqual(out.mode, im.mode)
|
||||
self.assertEqual(out.size, im.size)
|
||||
|
||||
filter(ImageFilter.BLUR)
|
||||
filter(ImageFilter.CONTOUR)
|
||||
|
@ -28,9 +28,9 @@ class TestImageFilter(PillowTestCase):
|
|||
filter(ImageFilter.MedianFilter)
|
||||
filter(ImageFilter.MinFilter)
|
||||
filter(ImageFilter.ModeFilter)
|
||||
filter(ImageFilter.Kernel((3, 3), list(range(9))))
|
||||
filter(ImageFilter.GaussianBlur)
|
||||
filter(ImageFilter.GaussianBlur(5))
|
||||
filter(ImageFilter.BoxBlur(5))
|
||||
filter(ImageFilter.UnsharpMask)
|
||||
filter(ImageFilter.UnsharpMask(10))
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ image enhancement filters:
|
|||
* **SHARPEN**
|
||||
|
||||
.. autoclass:: PIL.ImageFilter.GaussianBlur
|
||||
.. autoclass:: PIL.ImageFilter.BoxBlur
|
||||
.. autoclass:: PIL.ImageFilter.UnsharpMask
|
||||
.. autoclass:: PIL.ImageFilter.Kernel
|
||||
.. autoclass:: PIL.ImageFilter.RankFilter
|
||||
|
|
Loading…
Reference in New Issue
Block a user