Skip to main content
Tweeted twitter.com/#!/StackMma/status/633218999338315776
better title
Link
hftf
  • 959
  • 1
  • 7
  • 20

Inverse of Interpreter["Color"]: Convert a RGBColor to a natural language color name

a little more clarification
Source Link
hftf
  • 959
  • 1
  • 7
  • 20

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".

What is the best way to create the inverse function of Interpreter["Color"]? That function takes a natural language color as input and returns an RGBColor.

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".

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".

Source Link
hftf
  • 959
  • 1
  • 7
  • 20

Inverse of Interpreter["Color"]

What is the best way to create the inverse function of Interpreter["Color"]? That function takes a natural language color as input and returns an RGBColor.

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".