Python實現圖像模糊的三種方式(包含默認的標準模糊、高斯模糊和均值模糊)

可以用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)

原圖:
在這裏插入圖片描述

運行效果如下所示:

↓↓↓ img2(Pillow默認標準模糊):
在這裏插入圖片描述

↓↓↓ img3(高斯模糊):
在這裏插入圖片描述

↓↓↓ img4(均值模糊):
在這裏插入圖片描述





參考資料:

https://pillow.readthedocs.io/en/5.1.x/reference/ImageFilter.html#PIL.ImageFilter.GaussianBlur

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章