查找RGB值是否与Python中的另一个RGB值互补或相似?

时间:2019-01-19 16:18:51

标签: python-3.x colors

我有两个RGB数字。我正在尝试查找颜色是否“匹配”(从某种意义上说,衣服的颜色匹配或一致)。

我正在尝试创建一个函数来检查color1和color2是否彼此相似(或足够接近/在范围内)。

我还需要创建一个函数来检查color1和color2是否彼此互补。

我当前的代码如下:

from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
from colorharmonies import Color, complementaryColor, triadicColor, splitComplementaryColor, tetradicColor, analogousColor, monochromaticColor
from math import sqrt


def isComp(color1, color2):
    color1 = Color(color1, "", "")
    comp = complementaryColor(color1)
    diff = colDiff(comp, color2)
    #print(diff)
    return diff <= 20.0

def isAnalg(color1, color2):
    color1 = Color(color1, "", "")
    analg = analogousColor(color1)
    diff1 = colDiff(analg[0], color2)
    diff2 = colDiff(analg[0], color2)
    #print(diff)
    return diff1 <= 70.0 or diff2 <= 70.0

def colDiff(c1, c2):
    # Red Color
    color1_rgb = sRGBColor(float(c1[0]), float(c1[1]), float(c1[2]))
    # Blue Color
    color2_rgb = sRGBColor(float(c2[0]), float(c2[1]), float(c2[2]))
    # Convert from RGB to Lab Color Space
    color1_lab = convert_color(color1_rgb, LabColor)
    # Convert from RGB to Lab Color Space
    color2_lab = convert_color(color2_rgb, LabColor)
    # Find the color difference
    return delta_e_cie2000(color1_lab, color2_lab)

但是,此代码不起作用。谁能给我一个建议或可以使用的图书馆?还是一些代码?谢谢。

0 个答案:

没有答案