0
我需要修改它以執行簡化的灰度縮放計算。對於每個像素,計算彩色圖像的r,b,b值的平均值,並將所有三個r,g,b值設置爲該平均值。然後,我需要編寫一個setColor函數,期望兩個參數:一個圖像和一個包含3個整數的RGB元組。 setColor函數應該將圖像中的每個像素設置爲RGB元組顏色。它需要200像素寬×100像素高,允許用戶輸入RGB值的三個整數,打印提示「關閉圖像窗口繼續」,用圖像和用戶指定的顏色元組調用setColor,並繪製圖片。Python中的圖像處理
from images import Image
def grayscale(image):
"Converts the argument image to grayscale."""
for y in xrange(image.getHeight()):
(r, g, b) = image.getPixel(x, y)
r = int(r * 0.299)
g = int(g * 0.587)
b = int(b * 0.114)
lum = r + g + b
image.setPixel(x, y, (lum, lum, lum))
def main(filename = "smokey.gif")"
image = Image(filename)
print "Close the image window to continue."
image.draw()
graysclae(image)
print "Close the image window to quit."
image.draw()
main()
感謝錯字信息。 – user3457817
糟糕......我沒有完成。上面的問題是需要做的:修改程序以執行簡單的灰度縮放計算,然後編寫setColor函數。我不知道如何做任何一個。 – user3457817