Create an array of color name [message #89933] |
Thu, 01 January 2015 18:11  |
changliao1025
Messages: 4 Registered: January 2015
|
Junior Member |
|
|
I am using the coyote library.
I need to create an array of different color names.
Is there any convenient way to do that?
The colors should be best distributed across the loaded color table. I don't know whether it is practicable to name all of these colors within the color table. If not, what is the optional way to produce a set of distinct color names?
|
|
|
|
Re: Create an array of color name [message #89935 is a reply to message #89934] |
Fri, 02 January 2015 09:04  |
Jim Pendleton
Messages: 165 Registered: November 2011
|
Senior Member |
|
|
On Thursday, January 1, 2015 8:40:40 PM UTC-7, David Fanning wrote:
> changliao1025@gmail.com writes:
>
>> I am using the coyote library.
>> I need to create an array of different color names.
>> Is there any convenient way to do that?
>> The colors should be best distributed across the loaded color table. I don't know whether it is practicable to name all of these colors within the color table. If not, what is the optional way to produce a set of distinct color names?
>
> I can't think of any reason why you would have to do this. Why do you
> need an array of color names?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")
I'm with David on this. Not every RGB triplet of the 1.6 million possible has its own name, at least in the world of IDL. Thank goodness.
But if you're interested in matching RGB triplets against names that IDL knows about from the WC3 definitions, which total only 147, the following function may be of use to you. These are defined in the system variable !color.
function triplettoname, rgb
names = tag_names(!color)
outname = strarr(rgb.length/3)
foreach name, names, colorindex do begin
d = lonarr(outname.length)
for rgbindex = 0, outname.length - 1 do begin
if (total(abs(rgb[*, rgbindex] - long(!color.(colorindex)))) eq 0) then begin
outname[rgbindex] = name
break
endif
endfor
endforeach
return, outname
end
Here's an example, which shows the futility of the task for one of the popular color tables in IDL.
IDL> LOADCT, 15 ; Stern Special!
IDL> TVLCT, R, G, B, /GET
IDL> names = triplettoname(transpose([[r],[g],[b]]))
IDL> where(names ne '')
0 255
IDL> names
BLACK
WHITE
This means that of the 256 colors in the Stern Special color table, only two have RGB triplets that exactly match the list of color names known to IDL.
The code could be modified to find the "closest" match, but you'd need to define which color space "closest" represents, RGB, HLS, HSV, etc.
You may wish to construct your own color table using only named colors, if that's of value to you. However, a standard color table will have 256 colors and there are still only 147 with "standard" names.
Jim P.
|
|
|