2014-01-19 75 views
9

我一直在嘗試使用PIL模糊圖像。在Python中使用PIL模糊圖像

從我知道我需要複製圖像,然後更改每個像素到他周圍的像素,從原始圖片的平均 。所以我並沒有得到真正不遠, 我使用python的3.3倍

from PIL import Image 

img = Image.open("source") 
im = Image.copy(img) 

我知道如何使用putpixe,並得到一個像素的數據,但我無法弄清楚如何獲得 平均的像素周圍。

在此先感謝您的幫助!

回答

17

你可以這樣做:

blurred_image = original_image.filter(ImageFilter.BLUR) 

ImageFilter模塊更多選項。

你是正確的,你描述的過程會模糊圖像,並有過濾器,基本上直接做你的建議(*例如「,使用ImageFilter.Kernel方法,你的內核有恆定的權重)使用ImageFilter將更快,更容易,併爲您提供更多的模糊和更多的選擇

+8

還有ImageFilter.GaussianBlur(radius = 2),它比ImageFilter.BLUR好得多 – Sri

+0

當我做'blurred_image.show()'並嘗試將其保存爲位圖文件(.BMP),如何將其更改爲PNG或JPG格式? – 0x499602D2

+1

@ 0x499602D2:可以將其作爲單獨的問題提出;它與原始問題沒有關係。 – tom10