cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
d_barnett
Level IV

RGB Values to Color Names in Data Table

I have a data table that contains RGB values in separate columns and I want to have the name of the color ( or close to it) displayed in a seperate column.

One problem is that I can give some leeway in the values so they could be in a range of values so Black could be 0-0-0 or 5-0-0 or 0-5-0 or 0-0-5 or 5-5-0 to 5-5-5 etc. so a range of +/- 5 either side would be allowable

e.g.

   

Color NameRGB CODERGB
Black0-0-0000
Blue0-0-25500255
Light Blue173-216-230173216230
Yellow255-255-02552550
Orange255-165-02551650
Deep Pink255-20-14725520147
Pink255-192-203255192203
Brown165-42-421654242
1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: RGB Values to Color Names in Data Table

Nice example!

Here is an attempt to adapt John's script into a column formula:

Current Data Table() << New Column( "Color Name2",

  formula(

  Local(

  {colornames = {"Black", "Blue", "LightBlue", "Yellow", "Orange", "DeepPink", "Pink", "Brown"},

  rgb = [0 0 0,

  0 0 255,

  173 216 230,

  255 255 0,

  255 165 0,

  255 20 147,

  255 192 203,

  165 42 42]},

  colornames[Loc Min( V Sum( (rgb - Matrix( Repeat( {{:Red, :Green, :Blue}}, 8 ) ))` ^ 2 ) )]

)));

View solution in original post

10 REPLIES 10
d_barnett
Level IV

Re: RGB Values to Color Names in Data Table

I realised I probably didn't give enough information in the question. I have a table which contains the R,G & B values for a color from image analysis of a sample, I want JMP to 'translate' these into the nearest color name and put this into a separate column.

e.g. the output I have is similar to this

   

sampleRedGreenBlue
11654044
2136150102
3124160167
4124160158
5208254228
6202252226
7122158163
8118153153
9209254226
10210254234
11206253225
12202251223
13209254226
14211254233
15165192154

I want JMP to look through these values and tell me the nearest color, from either a different table containing a list of colors or from within a script.

So row 1 would say Brown, even though this doesn't exactly match the RGB for brown in the first table.

louv
Staff (Retired)

Re: RGB Values to Color Names in Data Table

Would something like this work?

Re: RGB Values to Color Names in Data Table

With some scripting help from melaniedrake,  I created and uploaded a script that finds the closes color and puts it in a column named "Color Name". RGB Color Matching Script. I hope it helps.

7435_RGBToColorNames.PNG


d_barnett
Level IV

Re: RGB Values to Color Names in Data Table

John,

I really like the look of this answer but unfortunately I can't access the document you've put on here. It comes up with unauthorised access.

Could you please post it here so I can get it please?

Regards

David

Jeff_Perkinson
Community Manager Community Manager

Re: RGB Values to Color Names in Data Table

Try the link in John's post again. I think it just hadn't been moderated yet.

It's available now.

RGB Color Matching Script

-Jeff

-Jeff

Re: RGB Values to Color Names in Data Table

Thanks Jeff.

Maybe I should have tried to attached the script directly here.

Sorry for the delay David. Please let me know if you have any questions about the code.

~John


Re: RGB Values to Color Names in Data Table

Hi ,

Can any one comment on how to get the color names for Color themes. e.g JMP Dark. how to get there color names and corresponding colors?

Thanks

Ram

Craige_Hales
Super User

Re: RGB Values to Color Names in Data Table

Not sure if this is what you mean...you can retrieve the RGB for the jmp named colors like this:


Color To RGB( "Dark Red" );


{0.627450980392157, 0.0352941176470588, 0.133333333333333}

You can also try Color To HLS.  The RGB numbers between 0 and 1 could be multiplied by 255 if you need numbers between 0 and 255.  0 is black.  The three numbers from Color To RGB are the red, green, and blue parts.

Craige
ms
Super User (Alumni) ms
Super User (Alumni)

Re: RGB Values to Color Names in Data Table

Nice example!

Here is an attempt to adapt John's script into a column formula:

Current Data Table() << New Column( "Color Name2",

  formula(

  Local(

  {colornames = {"Black", "Blue", "LightBlue", "Yellow", "Orange", "DeepPink", "Pink", "Brown"},

  rgb = [0 0 0,

  0 0 255,

  173 216 230,

  255 255 0,

  255 165 0,

  255 20 147,

  255 192 203,

  165 42 42]},

  colornames[Loc Min( V Sum( (rgb - Matrix( Repeat( {{:Red, :Green, :Blue}}, 8 ) ))` ^ 2 ) )]

)));