可以用Pillow库实现,示例代码(注意高斯模糊和均值模糊中配置的参数):
from PIL import Image, ImageFilter
img = Image.open('test.jpg')
img2 = img.filter(ImageFilter.BLUR)
img2.show()
img2.save('img2.jpg', quality=100)
img3 = img.filter(ImageFilter.GaussianBlur(10))
img3.show()
img3.save('img3.jpg', quality=100)
img4 = img.filter(ImageFilter.BoxBlur(10))
img4.show()
img4.save('img4.jpg', quality=100)
运行效果如下所示:
参考资料:
https://pillow.readthedocs.io/en/5.1.x/reference/ImageFilter.html#PIL.ImageFilter.GaussianBlur