gpt4 book ai didi

python - 图像处理 : Trying to make a photo negative?

转载 作者:行者123 更新时间:2023-12-01 09:55:22 24 4
gpt4 key购买 nike

我知道要使图像为负,您必须更改 RGB 值,以便从 255 中减去当前值。

我的以下代码有什么问题?

def negative(im):
height=len(im)
width = len(im[0])
for row in range(height):
for col in range(width):
red = im[row][col][0] - 255
green = im[row][col][1] - 255
blue = im[row][col][2] - 255
im[row][col]=[red,green,blue]
return im

它返回错误“TclError:无法解析颜色“#-1d-c-2””

最佳答案

你的问题是你得到了负数。我认为你应该做 255 - x而不是 x - 255

关于python - 图像处理 : Trying to make a photo negative?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29177898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com