Skip to content

Commit c743de6

Browse files
committed
v5
2 parents f183454 + 13444db commit c743de6

19 files changed

+264
-130
lines changed

README.md

+19-10
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ Column "_Source"
141141

142142
* https://cgit.freedesktop.org/xorg/app/rgb/tree/rgb.txt
143143

144-
* "duo" is noted for where there are two color names for the same color,
145-
such as "aqua" and "cyan"; "fuchia" and "magenta".
146-
The first of names alphabetically is returned.
144+
* Pantone (proprietary).
145+
146+
* https://en.wikipedia.org/wiki/Crayola#Colors
147+
148+
147149

148150
Column "_SVG" is used to designate names in SVG. Color numbers differs between SVG and X11 for
149151
"gray", "gray", "green", "maroon" and "purple".
@@ -152,21 +154,27 @@ SVG has "darkgray" while X11 does not.
152154

153155
* "SVG" is from https://www.w3.org/TR/SVG/types.html#ColorKeywords
154156

157+
"diff" is in the column if it's different than X11.
155158

156-
## Design alternatives #
159+
* "duo" is noted for where there are two color names for the same color,
160+
such as "aqua" and "cyan"; "fuchia" and "magenta".
161+
The first of names alphabetically is returned.
157162

158-
Additional columns may be added because there are other color names, such as:
163+
TOOL NOTE: To remove diacritical (Non-ASCII) characters from a file, consider:
164+
http://utils.paranoiaworks.org/diacriticsremover/
159165

160166
* <a target="_blank" href="http://us.labelpartners.com/pantone_coated_table.html">Pantone</a> (proprietary).
161167

162-
* https://en.wikipedia.org/wiki/Crayola#Colors
168+
## Design alternatives #
169+
170+
Add more color name sources (Sherwine Williams, etc.) - visit Home Depot
163171

164172
The pandas library for Python
165173
http://pandas.pydata.org/
166174

167175
http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.from_csv.html
168176

169-
can load a Dataframe from the csv file.
177+
Load a Dataframe from the csv file.
170178

171179
<pre>
172180
df = DataFrame.from_csv(rgb_combined.csv', sep='\t')
@@ -176,11 +184,12 @@ array = df.values # the array you are interested in
176184
Columns can be removed within the program using this call:
177185

178186
<pre>
179-
# RGB= np.delete(A, np.s_[3:5], axis=1) # remove columns 3 to 5.
187+
RGB= np.delete(A, np.s_[3:5], axis=1) # remove columns 3 to 5.
180188
</pre>
181189

182-
# Based on https://algorithmia.com/algorithms/deeplearning/CaffeNet/edit
183-
# Consider https://github.com/spotify/annoy/ for sharing memory.
190+
Based on https://algorithmia.com/algorithms/deeplearning/CaffeNet/edit
191+
192+
Consider https://github.com/spotify/annoy/ for sharing memory.
184193

185194

186195
## Clean-up #
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<p>This algorithm returns the name of the color that most closely matches the three numbers specifying a color (RGB).</p>
2+
<p>This API makes it easier for artists to identify color names so they have a way to use English words to describe colors.&nbsp;</p>
3+
<p style="color: rgb(85, 85, 85);background-color: rgb(255, 255, 255);"><span>This capability I also needed for a finger camera (IoT device) I'm working on which speaks the color name.</span><br></p>
4+
<h1><span style="color: inherit;"><b>Inputs and Outputs:</b></span><br></h1>
5+
<p>Colors are defined by 3 integers for RGB (Red Green Blue).&nbsp;<span>The program returns black if any number is larger than the 255 maximum value for each color.</span></p>
6+
<p>Additional information on colors is available on&nbsp;this author's decades of maniacal obsession with colors on computers at&nbsp;<a target="_blank" href="http://wilsonmar.com/1colors.htm" style="color: rgb(153, 99, 255);background-color: rgb(255, 255, 255);">http://wilsonmar.com/1colors.htm</a>.<br></p>
7+
<p><b>Example 1: SVG and X11</b><br></p>
8+
<h2><img src="https://cloud.githubusercontent.com/assets/300046/18149649/a88d4c6e-6f9e-11e6-9797-78618ae963f5.jpg"></h2>
9+
<pre><b>["221","184","137"]&nbsp;</b></pre>
10+
<p>is close to the color named "burlywood", a brownish color defined by the X11 standard.</p>
11+
<pre>{"burlywood",[222,184,135],"#DEB887","(+1,+0,-2)"}<br></pre>
12+
<p>"#DEB887" is the hex value used in CSS for display on <b>computer monitors</b>. Such colors may not be available in physical paint from a hardware store.</p>
13+
<p>"(+1,+0,+2)" is how far away the input color is from the named color returned.</p>
14+
<h3>Example 2: Pantone<br></h3>
15+
<pre><b>["123","163","217"]</b></pre>
16+
<p>is close to one of 1340 colors in the Pantone gamut output:</p>
17+
<pre><b>{"Pantone 659 C",[123,164,219],"#7BA4DB","(+0,+1,-2)"}</b></pre>
18+
<p>which is proprietary because of the work that went into figuring out what pigments paint stores need to mix to duplicate it accurately. For a fee, Pantone offers tools pros use to specify and measure a wide number of colors, such as <a target="_blank" href="https://www.visualnews.com/2016/06/15/worlds-ugliest-color)">"the world's ugliest color"</a> Pantone 448 C at ["74","65",42"]</p>
19+
<h3>Example 3: Company<br></h3>
20+
<pre><b>["0","119","181"]</b></pre>
21+
<p>is close to one of 29 corporate colors the algorithm can output:</p>
22+
<pre><b>{"Company LinkedIn blue",[0,119,181],"#0077B5","(+0,+0,+0)"}</b></pre>
23+
<p>The "(+0,+0,+0)" reflects a direct hit.<br></p>
24+
<h2>Credits:</h2>
25+
<p>The bulk of the work on this is to reconcile duplicate colors and color names from a variety of sources.&nbsp;</p>
26+
<ul>
27+
<li>The X11 and SVG standards were created to name colors that can best be displayed by display monitor hardware with minimal processing (at a time when displays had a smaller gamut than today).&nbsp;</li>
28+
<li>19 "Metro" colors are defined by Microsoft for Windows 8 from&nbsp;https://www.materialui.co/metrocolors</li>
29+
<li>18 Material Flat colors from&nbsp;<a target="_blank" href="https://www.materialui.co/flatuicolors" style="color: rgb(153, 99, 255);text-align: left;background-color: rgb(255, 255, 255);">https://www.materialui.co/flatuicolors</a></li>
30+
<li> 29 Company colors from&nbsp;https://www.materialui.co/socialcolors</li>
31+
<li>Pantone colors from&nbsp;http://us.labelpartners.com/pantone_coated_table.html</li>
32+
<li>US Federal Standard 595 from&nbsp;http://www.fed-std-595.com/FS-595-Paint-Spec.html</li>
33+
</ul>
34+
<p><span>Thanks to Ayush Pareek for his Python numpy genius.</span><br></p>
35+
<h2>Future enhancements:</h2>
36+
<ul>
37+
<li><p style="color: rgb(85, 85, 85);background-color: rgb(255, 255, 255);">Future uses of this API can identify colors that are printable on specific printers. Inclusion of additional color names will make this more useful to specify colors more accurately throughout the design lifecycle.</p></li>
38+
<li><span>Process JSON from another Algorithmia API as&nbsp;</span><span>part of a toolchain such as a follow-up to identification of predominant colors identified in a photograph by the&nbsp;<a href="https://github.com/fengsp/color-thief-py" style="color: rgb(153, 99, 255);background-color: rgb(255, 255, 255);">https://github.com/fengsp/color-thief-py</a>&nbsp;library</span></li>
39+
<li style="color: rgb(85, 85, 85);background-color: rgb(255, 255, 255);"><span>filter to respond only from specific gamuts (X11, SVG, Pantone)</span></li>
40+
<li><span>accept a wider range of input formats, such as "(0,175,219)"</span></li>
41+
<li><span>return a number of colors in the database</span></li>
42+
<li><span>input and return HCL color numbers (a different API)</span></li>
43+
<li><span>An app that reports the name of the color at the location tapped on a photo</span></li>
44+
</ul>

algorithmia_RGB2ColorName.py

-45
This file was deleted.

algorithmia_RGB2ColorName_v02.py

+49
Large diffs are not rendered by default.

algorithmia_RGB2ColorName_v03.py

+51
Large diffs are not rendered by default.

algorithmia_RGB2ColorName_v05.py

+51
Large diffs are not rendered by default.

companies.csv

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Google Red,#D62D20,214,45,32
2+
Google Green,#008744,0,135,68
3+
Google Blue,#0057E7,0,87,231
4+
Google Orange,#FFA700,255,167,0
5+
Amazon Red,#F84603,248,70,3
6+
Amazon Organge,#FF9616,255,150,22
7+
Amazon Yeallow,#FFCB00,255,203,0
8+
Amazon Blue,#003BB2,0,59,178
9+
Amazon Turquoise,#00FFDC,0,255,220

material.csv

-48
This file was deleted.

rgb2colorname.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,9 @@
11711171

11721172
# TODO: Test calls using variety of RGB input values
11731173
# TODO: Change to call argument with the point to find
1174-
pt = [221,183,134] # approximate to
1174+
# pt = [221,183,134] # approximate to
1175+
#pt = [0,0,0] # example needing zerofill
1176+
pt = [221,182,137] # = "burlywood","#DEB887"]
11751177
# pt = [222,184,135] # = "burlywood","#DEB887"]
11761178
# pt = [154,205,50] # = OliveDrab
11771179

@@ -1181,14 +1183,22 @@
11811183
# TODO: Calculate Hex from pt. (upper case letters)
11821184
# Instead of str(hex(pt[0])[2:]) in Python2, this is Python3 compatible:
11831185
s = '#' \
1184-
+ format(NearestRGB[0],'x') \
1185-
+ format(NearestRGB[1],'x') \
1186-
+ format(NearestRGB[2],'x')
1186+
+ format(NearestRGB[0],'x').zfill(2) \
1187+
+ format(NearestRGB[1],'x').zfill(2) \
1188+
+ format(NearestRGB[2],'x').zfill(2)
11871189
ColorHex = s.upper() # "#8B7355" # "#8B7355"
1188-
ColorDiff = '('+ str(pt[0]-NearestRGB[0])+','+str(pt[1]-NearestRGB[1])+','+str(pt[1]-NearestRGB[2])+')'
1190+
ColorDiff = \
1191+
'('+'{0:+d}'.format(NearestRGB[0]-pt[0]) \
1192+
+','+'{0:+d}'.format(NearestRGB[1]-pt[1]) \
1193+
+','+'{0:+d}'.format(NearestRGB[2]-pt[2]) \
1194+
+')'
1195+
try: ## TODO: try catch block per https://wiki.python.org/moin/HandlingExceptions
1196+
ColorName=HexNameDict[ColorHex]
1197+
except:
1198+
ColorName="not found"
11891199
print 'Nearest color name to input RGB ' \
11901200
+ str(pt) \
1191-
+ ' is "'+ HexNameDict[ColorHex] +'"' \
1201+
+ ' is "'+ ColorName +'"' \
11921202
+' '+ ColorHex \
11931203
+' '+ str(NearestRGB) \
11941204
+', '+ ColorDiff \

rgb_combined_v01.csv

+1-1
Large diffs are not rendered by default.

rgb_combined_v02.csv.txt

-2
This file was deleted.

rgb_combined_v03.csv

+1
Large diffs are not rendered by default.

rgb_combined_v03.csv.txt

+2
Large diffs are not rendered by default.

rgb_combined_v04.csv

+1
Large diffs are not rendered by default.

rgb_combined_v04.csv.txt

+2
Large diffs are not rendered by default.

rgb_combined_v05.csv

+1
Large diffs are not rendered by default.

rgb_combined_v05.csv.txt

+2
Large diffs are not rendered by default.

rgbcsv2colordict.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ def program(*args):
2525
except IndexError: # getopt.GetoptError:
2626
# print "Usage: " + sys.argv[0] + ' -i <inputfile> -o <outputfile>'
2727
# sys.exit(2)
28-
file_in = 'rgb_combined_v02.csv'
28+
file_in = 'rgb_combined_v03.csv'
2929

3030
# Exit if file_in not found:
3131
if os.path.exists(file_in) and os.access(file_in, os.R_OK):
3232
import csv, time
3333
with open(file_in, 'rU') as f:
3434
reader = csv.reader(f, delimiter=',')
3535
for i in reader:
36-
header_rows = '# '+time.strftime('%Y-%m-%d-%H:%M (local time)')+" "+sys.argv[0]+' START: inrowcount='+ str( sum(1 for _ in f) ) +'.'
36+
header_rows = '# '+time.strftime('%Y-%m-%d %H:%M (local time)')+" "+sys.argv[0]+' START: inrowcount='+ str( sum(1 for _ in f) ) +'.'
3737
print(header_rows)
3838
else:
39-
print('# '+time.strftime('%Y-%m-%d-%H:%M (local time)')+' '+sys.argv[0]+" ABORTED. Either file "+file_in+" is missing or is not readable.")
39+
print('# '+time.strftime('%Y-%m-%d %H:%M (local time)')+' '+sys.argv[0]+" ABORTED. Either file "+file_in+" is missing or is not readable.")
4040
exit(2)
4141

4242
# Provide default file_out name argument if not provided:
@@ -81,13 +81,12 @@ def program(*args):
8181
rownum=rownum+1
8282
print("}") # end with NewLine
8383

84-
footer_rows="# "+ time.strftime('%Y-%m-%d-%H:%M (local time)') +' '+ sys.argv[0] +" Output "+ str(rownum)+ ' rows.'
85-
print(footer_rows)
84+
footer_row1="# "+ time.strftime('%Y-%m-%d %H:%M (local time)') +' '+ sys.argv[0] +' '+ file_out +" output "+ str(rownum)+ ' rows.'
85+
print(" "+footer_row1)
8686
# Close the file every time:
8787
sys.stdout.close()
8888

8989
sys.stdout = stdout # Restore regular stdout.
90-
# End timer:
91-
elapsed = timeit.default_timer() - start_time
92-
print("# "+ time.strftime('%Y-%m-%d-%H:%M (local time)') +' '+ sys.argv[0] +" END: ran for "+ "{:.2f}".format(elapsed * 1000 )+ ' secs.')
93-
print(footer_rows)
90+
print(footer_row1)
91+
elapsed = timeit.default_timer() - start_time # End timer:
92+
print("# "+ time.strftime('%Y-%m-%d %H:%M (local time)') +' '+ sys.argv[0] +" END: ran for "+ "{:.2f}".format(elapsed * 1000 )+ ' secs.')

rgbcsv2rgbarray.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# rgbcvs2colorarray.py
2+
# rgbcvs2rgbarray.py
33
44
# Usage: rgbcvs2colorarray.py rgb_combined.csv
55
# Oputput: A = array([[222,43,221],[2,11,222], ... ])
@@ -24,7 +24,7 @@ def program(*args):
2424
except IndexError: # getopt.GetoptError:
2525
# print "Usage: " + sys.argv[0] + ' -i <inputfile> -o <outputfile>'
2626
# sys.exit(2)
27-
file_in = 'rgb_combined_v02.csv'
27+
file_in = 'rgb_combined_v05.csv'
2828

2929
# Exit if file_in not found:
3030
if os.path.exists(file_in) and os.access(file_in, os.R_OK):
@@ -39,20 +39,18 @@ def program(*args):
3939
exit(2)
4040

4141
# Provide default file_out name argument if not provided:
42-
if __name__ == "__main__":
43-
#def main(argv):
42+
if __name__ == "__main__": #def main(argv):
43+
# Name output file by appending .txt to the name:
4444
try:
4545
arg1 = sys.argv[2]
46-
file_out = sys.argv[2]
46+
file_out = sys.argv[2] +'.'+ file_in + '.txt'
4747
except IndexError: # getopt.GetoptError:
48-
# Name output file by appending .txt to the name:
4948
file_out = file_in + '.txt'
5049

5150
# Send STDOUT to a file:
5251
stdout = sys.stdout # remember the handle to the real standard output.
5352
sys.stdout=open( file_out,"w")
5453

55-
5654
# Print in yml format:
5755
import csv
5856
# 'rU' means open in universal-newline mode needed on Macs:
@@ -82,7 +80,7 @@ def program(*args):
8280
rownum=rownum+1
8381
print("])") # with NewLine
8482

85-
footer_rows="# "+ time.strftime('%Y-%m-%d-%H:%M (local time)') +' '+ sys.argv[0] +" Output "+ str(rownum)+ ' rows.'
83+
footer_rows=" # "+ time.strftime('%Y-%m-%d-%H:%M (local time)') +' '+ sys.argv[0] +" Output "+ str(rownum)+ ' rows.'
8684
print(footer_rows)
8785
# Close the file every time:
8886
sys.stdout.close()
@@ -91,4 +89,4 @@ def program(*args):
9189
# End timer:
9290
elapsed = timeit.default_timer() - start_time
9391
print("# "+ time.strftime('%Y-%m-%d-%H:%M (local time)') +' '+ sys.argv[0] +" END: ran for "+ "{:.2f}".format(elapsed * 1000 )+ ' secs.')
94-
print(footer_rows)
92+
print(' '+footer_rows)

0 commit comments

Comments
 (0)