from PIL import Image, ImageFilter
# 打开一个 jpg 图像文件,注意是当前路径:
im = Image.open(‘Penguins.jpg’)
# 模糊
im2 = im.filter(ImageFilter.BLUR)
# 模糊可设置模糊的程度
im22 = im.filter(ImageFilter.BoxBlur(200))
# 轮廓滤波
im3 = im.filter(ImageFilter.CONTOUR)
# 边缘增强滤波(锐化)
im4 = im.filter(ImageFilter.EDGE_ENHANCE)
# 浮雕滤波
im5 = im.filter(ImageFilter.EMBOSS)
# 寻找边缘信息的滤波
im6 = im.filter(ImageFilter.FIND_EDGES)
im2.save(‘BLUR.jpg’, ‘jpeg’)
im3.save(‘CONTOUR.jpg’, ‘jpeg’)
im4.save(‘EDGE_ENHANCE.jpg’, ‘jpeg’)
im5.save(‘EMBOSS.jpg’, ‘jpeg’)
im6.save(‘FIND_EDGES.jpg’, ‘jpeg’)
im22.save(‘BoxBlur(200).jpg’, ‘jpeg’)
图片如下