What is the best way to create the inverse function of Interpreter["Color"]
? That function takes a natural language color name like "blue"
as input, and returns an RGBColor
as output.
Here I whipped up a basic classifier based on Mathematica's built-in color symbols:
trainingset =
(List @@ ColorConvert[Symbol@#, "RGB"] -> #) & /@
StringSplit[
"Red,Green,Blue,Black,White,Gray,Cyan,Magenta,Yellow,Brown,Orange,Pink,Purple", ","]
testset = {
RGBColor[0., 0., 0., 0.], RGBColor[0., 0., 0., 1.],
RGBColor[0., 0.2196, 0.7215, 1.], RGBColor[0., 0.4235, 0.2078, 1.],
RGBColor[0., 0.4784, 0.2392, 1.], RGBColor[0.8078, 0.0666, 0.1490, 1.],
RGBColor[1., 1., 1., 1.], RGBColor[1., 0.8705, 0., 1.],
RGBColor[0.2039, 0.6980, 0.2, 1.],RGBColor[0.0039, 0., 0.4, 1.]
}
c = Classify[trainingset]
c /@ Take[#, 3] & /@ (List @@ ColorConvert[#, "RGB"] & /@ testset)
(*
{"Black", "Black", "Blue", "Black", "Green", "Red", "White", "Yellow", "Green", "Black"}
*)
I'm not sure how well it works in general, but the darker colors seem to come out as "Black"
.
ColorDistance[]
function could be useful here? $\endgroup$"Named"
sets:Interpreter["Color"] /@ {"amaranth","bronze","blond"}
for example. $\endgroup$