mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
highlevel api
This commit is contained in:
parent
5861a46a54
commit
53c8352f39
|
@ -441,3 +441,20 @@ def unsharp_mask(im, radius=None, percent=None, threshold=None):
|
|||
return im.im.unsharp_mask(radius, percent, threshold)
|
||||
|
||||
usm = unsharp_mask
|
||||
|
||||
|
||||
def box_blur(image, radius):
|
||||
"""
|
||||
Apply box blur to given image. Box blur is operation where
|
||||
each pixel becomes the average value of pixels in given radius.
|
||||
Supports float radius and very large ones. Fast implementation,
|
||||
works in linear time relative to the radius.
|
||||
|
||||
:param image: The image to blur.
|
||||
:param radius: Size of the box in one direction. Radius 0 does not blur,
|
||||
radius 1 takes 1 pixel in all directions, i.e. 9 pixels in total.
|
||||
:return: An image.
|
||||
"""
|
||||
image.load()
|
||||
|
||||
return image._new(image.im.box_blur(radius))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import Image, ImageFilter
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
|
||||
sample = Image.new("L", (7, 5))
|
||||
|
@ -14,7 +14,12 @@ sample.putdata(sum([
|
|||
|
||||
|
||||
class TestBoxBlurApi(PillowTestCase):
|
||||
pass
|
||||
|
||||
def test_imageops(self):
|
||||
i = ImageOps.box_blur(sample, 1)
|
||||
self.assertEqual(i.mode, sample.mode)
|
||||
self.assertEqual(i.size, sample.size)
|
||||
self.assertIsInstance(i, Image.Image)
|
||||
|
||||
|
||||
class TestBoxBlur(PillowTestCase):
|
||||
|
|
|
@ -229,8 +229,8 @@ ImagingBoxBlur(Imaging im, Imaging imOut, float radius)
|
|||
HorizontalBoxBlur32(im, temp, radius);
|
||||
}
|
||||
|
||||
/* Blur in same direction transposed result from previout step.
|
||||
Reseult will be transposes again. We'll get original image
|
||||
/* Blur transposed result from previout step in same direction.
|
||||
Reseult will be transposed again. We'll get original image
|
||||
blurred in both directions. */
|
||||
if (strcmp(im->mode, "L") == 0) {
|
||||
HorizontalBoxBlur8(temp, imOut, radius);
|
||||
|
|
Loading…
Reference in New Issue
Block a user