• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This API gives closest approximation of an RGB value to a set of color names. It is highly optimized for performance and scalability.

Optimized RGB-To-ColorName API

Authors- Wilson Mar, Ayush Pareek

TL;DR- Not all colours present in the physical world have an exact representation in different forms of digital spectrum and platforms. Artists, E-commerce websites, Companies etc. desire precision while publishing their work, products and logos. Some colors may not be reproducible on monitors and on printers in pigments available. This API gives closest approximation of an RGB value to a set of colour names. Its highly optimized for performance and scalibility.

0

##Hosted at :- https://algorithmia.com/algorithms/wilsonmar/RGB2ColorName

This API makes it easier for artists to identify color names to use English words to describe colors. Colors are defined by 3 integers for RGB (Red Green Blue). The program returns black if any number is larger than the 255 maximum value for each color. The 256x256x256 = 16,777,216 possible individual color values.

yo

Currently, this API knows about 2,790 unique color names widely defined publicly.

The three dimensions involved in specifying a color makes it difficult to manually identify the closest point with a color name.

The bulk of the work on this API was in compiling the color names and their RGB coordinates. There were many duplicates in both names and color coordinates.

##Inputs and Outputs: The colors of a few famous social media and tech companies are known by this API, thanks to https://www.materialui.co/socialcolors. Additional companies have been added into this API, such as Google, Amazon, and IBM.

###Example 1: IBM Blue and Hex equivalent Organizations need to precisely specify the colors in their logo so that vendors accurately render it online, in packaging, etc..

In https://www-03.ibm.com/press/us/en/photo/20190.wss IBM defines the color of its trademark Blue color as "PMS 2718C; Process equivalent: Cyan 75%, Magenta 43%, Yellow 0%, Black 0%; RGB equivalent: Red 90, Green 135, Blue 197; Broadcast equivalent: Red 22%, Green 42%, Blue 70%.: Let's see if this API recognizes it:

1

"#5A87C5" is the hex equivalent of the RGB color found.

"(+0,+0,+0)" means that the color found is a direct hit of the color input.

###Example 2: Pantone

So for many years, designers make use of the Pantone palette of 1,340 colors, which are proprietary because of the work that went into figuring out what mix of pigments of paints and dyes are needed to duplicate it accurately.

Pantone's "PMS" colors are from http://us.labelpartners.com/pantone_coated_table.html.

For a fee, Pantone offers tools pros use to specify and measure a wide number of colors, such as "the world's ugliest color" Pantone 448 C at ["74","65",42"], which governments use to discourage smoking.

###Example 3: X11, SVG, CSS

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

2 3

####Credits: The bulk of the work on this is to reconcile duplicate colors and color names from a variety of sources.

19 "Metro" colors are defined by Microsoft for Windows 8 from https://www.materialui.co/metrocolors 18 Material Flat colors from https://www.materialui.co/flatuicolors 29 Company colors from https://www.materialui.co/socialcolors Crayola colors US Federal Standard 595 from http://www.fed-std-595.com/FS-595-Paint-Spec.html Thanks to Ayush Pareek for his Python numpy genius.

This capability is also needed for a finger camera (IoT device) which speaks the color name.

####Tags- accessibility color color palette data transformation mapping python


DESIGN AND WORKING STRUCTURE

4

The program rgb2colorname.py invokes an algorithm that identifies the name of a color closest to an RGB value provided as input.

  • Input: ["221","185","135"] are RGB (Red Green Blue) values between 0 - 256.

    Alternative HCL representations are processed by another API.

  • Output: Nearest color name to input RGB [221, 183, 134] is "burlywood" #DEB887 [222 184 135]

    TODO: Perhaps also return the 3 distances to the input.

    And an accuracy score, which is always 100% since the calculation is done mathematically.

Usage Expected

The utility is expected to enable artists to more accurately specify the color of their works in text search engines within Google, Instagram, Etsy, Amazon, Walmart, Jet, and other ecommerce site so that others can better match artwork to their design intentions.

However, this may not see much use as many words in the color names have different associations in different parts of the world. And artists probably desire more precision in color names than the 571 colors in the gamut.

And some colors may not be reproducible on printers and in pigments available.

Nevertheless, this is a fun exercise for us to demonstrate use of Python features:

  • numpy library's closest-neighbor functions
  • definition of arrays and dictionary for stand-alone data values (no external dependencies)
  • calculate hex from decimal
  • string lookup in dictionary
  • naming conventions and documentation for teamwork

All different techniques were used in https://algorithmia.com/algorithms/vagrant/snapToMaterial/edit

We are also using this exercise to demostrate our ability to incorporate algorithms into Algorthmia. Specifically at https://algorithmia.com/algorithms/wilsonmar/RGB2ColorName (a private service during development).

Building on this achievement will be more distruptive tools such as identify colors that are printable by specific printers, VR to help visualize 3D color spaces, and ML outputs that recognize colors with more accuracy.

Processing

  1. The 3-dimensional array in the program rgb2colorname.py (as stored in GitHub) is constructed by running the rbgcsv2array.py program (also in this GitHub), which reads the rbg_combined_v01.csv file.

    This is necessary because changes can occur in the list of color names and associated points in 3D color space.

  2. The array generated is pasted into program rgb2colorname.py.

  3. Program rgb2colorname.py in invoked with an array. a set of 3 RGB numbers plus the hex equivalent and the color name title.

  4. The numpy functions identify the nearest neighbor to the array input, and return 3 numbers.

  5. The 3 numbers returned is used to calculated the hex code.

  6. The hash code is used to lookup the name of the color (and later, its HCL code).

  7. Information associated with the color found (RGB numbers, hex code, color name) is returned to the caller.

rbg_combined.csv

This work draws on prior work by Wilson Mar on colors at http://wilsonmar.com/1colors.htm#ColorNamez

Column name text in the heading line begin with an underline so each sorts to the top during sorts.

Column "_Hex" is the Hexadecimal combination of 3 RGB() hex of 2 characters each. The column contains a leading dash because of the bad way Microsoft Excel handles hex numbers.

The single # (hash mark) makes Excel see the six-characters as text rather than numbers.

The conversion to hex #5A87C5 was done using this Excel formula:

   =concatenate("#",DEC2HEX(B678,2),DEC2HEX(C678,2),DEC2HEX(D678,2))
   

To convert to hex can be done using this Excel formula:

   =concatenate(HEX2DEC(MID(A2,2,2))
   

Column "_Title" contains color names that in "Title" case, with a capitalize first letters of every word. SVG has names in all lower case.

Column "_Name" are dashes between compound words for X11.

Column "_Gray" contains either "gray" or "grey" to differentiate then alternate spellings. X11 is defined with both, so it doubles the number of colors defined as gray/grey.

Since we are using the colors as a look-up, we should only have one.

"Grey" is used in Great Britain and areas that use UK English. "Gray" is used primarily in the United States and other areas that use US English. So we only have "Gray" in this program to avoid doubling of gray/grey color name definitions.

Column "_seq" sequences conflicting _Hex codes. A color has "1" in this field if it has no conflicts. This is the only color put in the array and dictionary. Conflicting colors are given "2", "3", etc. so they are not lost for future use.

This field is used as the secondary soft after _Hex.

A number must be used because Excel sorts blanks under cells with values (the opposite of how databases do sorting).

Column "_Source"

Column "_SVG" is used to designate names in SVG. Color numbers differs between SVG and X11 for "gray", "gray", "green", "maroon" and "purple". These exceptions have "diff" in X11 lines. SVG has "darkgray" while X11 does not.

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

  • "duo" is noted for where there are two color names for the same color, such as "aqua" and "cyan"; "fuchia" and "magenta". The first of names alphabetically is returned.

TOOL NOTE: To remove diacritical (Non-ASCII) characters from a file, consider: http://utils.paranoiaworks.org/diacriticsremover/

Other ideas for Alogrithmia: http://textmechanic.com/text-tools/numeration-tools/online-tally-counter/

Design alternatives

  1. Add more color name sources (Sherwin Williams, etc.) - visit Home Depot

  2. Load csv file as Dataframe - the pandas library for Python http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.from_csv.html

df = DataFrame.from_csv(rgb_combined.csv', sep='\t')
array = df.values # the array you are interested in

Columns can be removed within the program using this call:

 RGB= np.delete(A, np.s_[3:5], axis=1) # remove columns 3 to 5.

Based on https://algorithmia.com/algorithms/deeplearning/CaffeNet/edit

Consider https://github.com/spotify/annoy/ for sharing memory.

Clean-up

Please remove these intermediate attempts:

  • rgb2nearestvalue.py
  • rgb_color_k_nearest.py
  • rgb2color_runtime_error.py
  • rgb2nearestcolor.py
  • rgbcsv2array.py

More Repositories

1

Sentiment-Analysis-Twitter

🎓RESEARCH [NLP 💭] We use different feature sets and machine learning classifiers to determine the best combination for sentiment analysis of twitter.
Python
761
star
2

HandWritingRecognition-CNN

This CNN-based model for recognition of hand written digits attains a validation accuracy of 99.2% after training for 12 epochs. Its trained on the MNIST dataset on Kaggle.
Python
124
star
3

Consensus-Based-Summarizer

🎓RESEARCH [NLP 💬] This is an implementation of "Automatic Consensus-Based Text Summarizer" along with text-organizing capabilities that can generate genre-specific, generic or user-configured summaries of a large amount of unorganized text. We are currently using a number of independent text-mining algorithms based on different statistical models to compute the summaries and combining them using configurable consensus techniques.❗💥
C++
97
star
4

NeuralNetwork-ImageQA

This is a python and keras implementation of the VIS+LSTM visual question answering model.
Python
47
star
5

Two-pass-Assembler

💻COMPUTER ARCHITECTURE💳 Designed a 32-bit ISA and implemented a two pass assembler using C code to demonstrate how assembly language computation occurs with the help of different sets of instructions and different addressing modes defined in ISA. It converted Assembly Language code into Machine Language code and then using the machine language code generated executed the program. 🎹
C
47
star
6

Ngram-Graphs

🎓RESEARCH [NLP] Analysis of N-gram Graphs and their applications in the domain of Text Classification and Extraction based Summarization
Java
37
star
7

Multi-Document-Summarization

Neural Network based MDS
Perl
27
star
8

DataScienceWork

This repository contains some of my projects in Exploratory Data Analysis, Statistical Inference, Regression Models and other aspects of Practical Machine Learning
Jupyter Notebook
11
star
9

FoodGeek

🍴🍟Agile Software Dev. Project☕ Full SCRUM Workflow Reports and Professional Software Development of a Food Ordering Website.
CSS
7
star
10

RedMacDB

The NEXT-GENERATION Resilient, Elastic, Distributed, Message Driven and Concurrent Reactive Storage Service
Scala
6
star
11

News-Feed-and-Digest

🐮JAVA DESKTOP APPLICATION with mySQL DB🐰 This application can fetch news 📰 in the form of summaries from news agencies around the world. The news items are categorized 📖 based on topics and the user can signup for an account which will give him access to personalized news based on his preference.
Java
6
star
12

Cool-Item-Cataloger

Item Catalog Application with Authentication, Registration and Categorization
Python
3
star
13

HackerRank

C++
3
star
14

HateSpeechDetector

Hate Speech Detector App using Xamarin
C#
1
star
15

MT-Assignment-2

TypeScript
1
star
16

Twilio-SMS

Twilio sms client for Node.js
JavaScript
1
star
17

FoodGeek.github.io

JavaScript
1
star