【发布时间】:2021-02-01 03:50:31
【问题描述】:
我是 Python 新手,在谷歌搜索公式后无法将此图像转换为灰度。我应用错了吗?无论我尝试什么,我的图像都会染成绿色。
0.2989 * R + 0.5870 * G + 0.1140 * B
import image
img= image.Image("luther.jpg")
win= image.ImageWin(img.getWidth(), img.getHeight())
img.draw(win)
img.setDelay(1,100)
for row in range(img.getHeight()):
for col in range(img.getWidth()):
p=img.getPixel(col, row)
newRed= 0.2989*p.getRed()
newGreen= 0.5870*p.getGreen()
newBlue= 0.1140*p.getBlue()
newpixel= image.Pixel(newRed, newGreen, newBlue)
img.setPixel(col, row, newpixel)
img.draw(win)
win.exitonclick()enter code here
【问题讨论】:
-
有趣的事实,大多数人使用这些来自模拟屏幕的权重,没有人考虑到数字屏幕已经被称重......如果没有,那么 ffffff(rgb 的最大强度)看起来不会是白色的,因此这些权重可能是多余的。无论如何,请注意,灰度 rgb 都需要相同的值。