I am trying to write a simple function which based on RGB code is returning name of the closest "reference" colour.
Based on other SO question, I am converting RGB to CIE LAB and calculating distance between input colour and reference colours. Then I am searching for the smallest distance and taking corespondent colour.
Unfortunately suggested solution works only partially. Given the "dark orange" colour is interpreted as red.
I tried to improve it and I changed deltaE_ciede76 to deltaE_ciede94 and deltaE_ciede00, based on this article.
Do you have any idea how they solve this problem on the below page?: https://convertingcolors.com/rgb-color-247_104_8.html - please scroll down to the section: Details
It is written: The colour can be described as dark saturated orange.
Could you give me any advice?
simple program:
import numpy as np
from skimage.color import rgb2lab, deltaE_ciede94
def identify_colour(rgb_colour):
reference = {
"red" : [53.23, 80.11, 67.22], # https://convertingcolors.com/cielab-color-53.23_80.11_67.22.html
"orange": [74.93, 23.94, 78.96], # https://convertingcolors.com/cielab-color-74.93_23.94_78.96.html
}
input_colour = rgb2lab([[rgb_colour / 255]])
selected = None
d = {}
for colour, value in reference.items():
basic_lab = np.asarray(value)
distance = deltaE_ciede94(basic_lab, input_colour)
d[colour] = distance
selected = min(d, key=d.get)
print("selected: ", selected)
print(d)
return selected
def main():
rgb_colour = np.array([247, 104, 8]) # https://convertingcolors.com/rgb-color-247_104_8.html
identify_colour(rgb_colour)
if __name__ == '__main__':
main()
I can not comment, just answer but as it is my site I wanted to comment on
"Do you have any idea how they solve this problem on the below page?: https://convertingcolors.com/rgb-color-247_104_8.html - Please scroll down to the section: Details."
Have a look at this talk and the slides; this helped me implement this feature: https://www.dotconferences.com/2018/11/david-desandro-read-color-hex-codes