Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
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 Name RGB CODE R G B Black 0-0-0 0 0 0 Blue 0-0-255 0 0 255 Light Blue 173-216-230 173 216 230 Yellow 255-255-0 255 255 0 Orange 255-165-0 255 165 0 Deep Pink 255-20-147 255 20 147 Pink 255-192-203 255 192 203 Brown 165-42-42 165 42 42
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User

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 ) )]

)));

10 REPLIES 10
Highlighted
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

 sample Red Green Blue 1 165 40 44 2 136 150 102 3 124 160 167 4 124 160 158 5 208 254 228 6 202 252 226 7 122 158 163 8 118 153 153 9 209 254 226 10 210 254 234 11 206 253 225 12 202 251 223 13 209 254 226 14 211 254 233 15 165 192 154

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.

Highlighted
Staff (Retired)

Re: RGB Values to Color Names in Data Table

Would something like this work?

Highlighted
Staff

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.

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

Highlighted
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
Highlighted
Staff

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

Highlighted
Level IV

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

Highlighted
Staff (Retired)

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
Highlighted
Super User

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 ) )]

)));

Article Labels

There are no labels assigned to this post.