温馨提示×

Pillow怎么对图像应用径向模糊效果

小亿
111
2024-05-23 10:59:07
栏目: 编程语言

要对图像应用径向模糊效果,可以使用Pillow库中的ImageFilter模块。以下是一个示例代码,演示如何在Python中使用Pillow库对图像应用径向模糊效果:

from PIL import Image, ImageFilter # 打开要处理的图像文件 image = Image.open('example.jpg') # 应用径向模糊效果 blurred_image = image.filter(ImageFilter.GaussianBlur(radius=5)) # 保存处理后的图像文件 blurred_image.save('blurred_example.jpg') # 显示原始图像和处理后的图像 image.show() blurred_image.show() 

在上面的代码中,首先使用Image.open()方法打开要处理的图像文件。然后,使用filter()方法和ImageFilter.GaussianBlur()函数来应用径向模糊效果,其中radius参数指定了模糊半径。最后,使用save()方法保存处理后的图像文件,并使用show()方法显示原始图像和处理后的图像。

0