我正在尝试创建一对可以增加或减少图像整体色彩饱和度的函数。我知道“饱和度”本质上是指“远离或接近灰色”,所以我需要增加或减少 RGB 通道,但我不能平等地完成它们(即 r * 2、g * 2、b * 2) 因为那只会使图像更亮。
我试图使用这里给出的公式:http ://www.georeference.org/doc/colors_as_hue_saturation_and_brightness.htm 但是当我尝试在我的代码中使用它时,图像几乎完全是黑色的,有一些黄色斑点。
这是我迄今为止尝试过的:
def upSaturation(pictu):
'''Takes a picture and increases the overall color saturation'''
satuP = duplicatePicture(pictu)
for pixel in getPixels(satuP):
r = getRed(pixel)
g = getGreen(pixel)
b = getBlue(pixel)
mn = min(r, g, b)
mx = max(r, g, b)
lht = (mx + mn) / 2
if lht <= 128:
satu = 255 * ((mx - mn) / (mx + mn))
clr = makeColor(r * satu, g * satu, b * satu)
setColor(pixel, clr)
else:
sat = 255 * ((mx - mn) / (511 - (mx + mn)))
color = makeColor(r * sat, g * sat, b * sat)
setColor(pixel, color)
show(satuP)
return satuP
我也尝试过只使用 makeColor(sat, sat, sat) ,但它完全是黑色的,带有一些白色的斑点。我不确定此时还能做什么。我将不胜感激一些指导。