Python中pillow库的滤镜

摘要

Python中pillow库中常用的几个滤镜方法

pillow库常用滤镜方法

滤镜名称 方法
模糊滤镜 ImageFilter.BLUR
铅笔轮廓滤镜 ImageFilter.CONTOUR
浮雕滤镜 ImageFilter.EMBOSS
边缘凸显滤镜 ImageFilter.EDGE_ENHANCE
边缘凸显滤镜(加强) ImageFilter.EDGE_ENHANCE_MORE
只保留滤镜 ImageFilter.FIND_EDGES
锐化滤镜 ImageFilter.SHARPEN
平滑滤镜 ImageFilter.SMOOTH
平滑滤镜(加强) ImageFilter.SMOOTH_MORE

代码

from PIL import Image, ImageFilter # 导入 pillow库 的 Image,ImageFilter
import matplotlib.pyplot as pil   # 导入matplotlib库的 pyplot

img = Image.open('吒儿.jpg')  # 打开图片Python文件需要与图片在同一个文件夹

# 滤镜处理
filter = [
    ImageFilter.BLUR, # 模糊滤镜
    ImageFilter.CONTOUR, # 铅笔轮廓滤镜
    ImageFilter.EMBOSS,  # 浮雕滤镜
    ImageFilter.EDGE_ENHANCE,  # 边缘凸显滤镜
    ImageFilter.EDGE_ENHANCE_MORE,  # 边缘凸显滤镜(加强)
    ImageFilter.FIND_EDGES,  # 只保留滤镜
    ImageFilter.SHARPEN,  # 锐化滤镜
    ImageFilter.SMOOTH ,# 平滑滤镜
    ImageFilter.SMOOTH_MORE,  # 平滑滤镜(加强)
]

for i in range(len(filter)):
    img_2 = img.filter(filter[i])
    pil.imshow(img_2)
    pil.show()

显示效果

模糊滤镜
Python中pillow库的滤镜_第1张图片

铅笔轮廓滤镜
Python中pillow库的滤镜_第2张图片
浮雕滤镜
Python中pillow库的滤镜_第3张图片

边缘凸显滤镜
Python中pillow库的滤镜_第4张图片

边缘凸显滤镜(加强)
Python中pillow库的滤镜_第5张图片

只保留滤镜
Python中pillow库的滤镜_第6张图片

锐化滤镜
Python中pillow库的滤镜_第7张图片

平滑滤镜
Python中pillow库的滤镜_第8张图片
平滑滤镜(加强)
Python中pillow库的滤镜_第9张图片

你可能感兴趣的:(Python中pillow库的滤镜)