温馨提示×

怎么用Python和Pillow库对图像进行滤镜处理

小亿
85
2024-04-29 18:32:50
栏目: 编程语言

要使用Python和Pillow库对图像进行滤镜处理,首先需要安装Pillow库。可以使用以下命令来安装Pillow:

pip install Pillow

接下来,可以使用以下代码示例来对图像进行滤镜处理:

from PIL import Image, ImageFilter

# 打开图像文件
image = Image.open('input.jpg')

# 应用滤镜
filtered_image = image.filter(ImageFilter.BLUR)

# 保存处理后的图像
filtered_image.save('output.jpg')

# 显示处理后的图像
filtered_image.show()

在这个示例中,我们首先打开一张名为’input.jpg’的图像文件,然后应用一个模糊滤镜并保存为名为’output.jpg’的文件,最后显示处理后的图像。

除了模糊滤镜,Pillow库还提供了许多其他滤镜效果,可以根据需要选择不同的滤镜效果来处理图像。更多关于Pillow库的信息可以参考官方文档:https://pillow.readthedocs.io/en/stable/

0