我有一張圖片,我想縮小它。因此,我寫了這樣的代碼:在python中的圖像處理 - 不工作以及我認爲
def scaling_down(ima, value):
###~Scaling down the image by a value~###
value = int(value)
width, height = ima.size
mat_m = ima.load()
width2 = (int(width) + 1)/value
height2 = (int(height)+1)/value
out1 = Image.new('L',(width2,height2))
out_the_pix = out1.load()
for x in range(0,width,value):
for y in range(0,height,value):
out_the_pix[x/value,y/value] = mat_m[x,y]
return out1
這個值是我想縮放圖像的多少。 但是,當我選擇的值大於2時,出現錯誤。我需要選擇值2來接收沒有錯誤。你能幫我找到原因嗎?
定義的 「錯誤」。 –
這是PIL嗎?你應該修復你問題中的縮進。 – moooeeeep
DRY,scikit-image有這個功能。 http://scikit-image.org/docs/dev/api/skimage.transform.html?highlight=hough#skimage.transform.downscale_local_mean – M4rtini