Algorithmia Blog

Introduction to Color Scheme Extraction

As an artist, inspiration can come from anywhere: a particular texture, a design, or even a color scheme.

Instead of spending hours painstakingly extracting the hex codes from all of the important sections of an image, what if there was a way to automatically extract the most important parts of an image?

Color Scheme extraction is able to find the most relevant colors in seconds.

What Is Color Scheme Extraction?

Color Scheme extraction is an open source algorithm using the scikit-learn framework that extracts color schemes from images. It does this by using an unsupervised machine learning technique called k-means clustering that iteratively classifies groups of similar pixels and returns the centroid or most archetypical pixel from each different subgroup.

Pixel clusters are generated with varying initial conditions and scored on overall accuracy until the iteration limit is reached. The best pixel cluster model is then selected, the centroids of each cluster (cluster_centers) are extracted and the centroid pixel color values are returned as the color scheme palette.

Why You Need Color Scheme Extraction

Complex images with gradients just have too many colors to be able to easily extract a representative palette. However, with an automated color scheme extraction tool, it’s possible to set the color scheme for your favorite app or even a product like a car or motorcycle from just a single picture!

How Do I Use Color Scheme Extraction?

Sample Input:

input = {"url": "http://i.imgur.com/JO5sjnG.jpg"}

client = Algorithmia.client('YOUR_API_KEY')
result = client.algo('vagrant/ColorSchemeExtraction/0.2.x').pipe(input).result

Sample Output:

{
"colors": [
{"hex": "#342743", "rgb": [52, 39, 67]},
{"hex": "#fa63c7", "rgb": [250, 99, 199]},
{"hex": "#a67995", "rgb": [166, 121, 149]},
{"hex": "#0b101d", "rgb": [11, 16, 29]},
{"hex": "#1f4b61", "rgb": [31, 75, 97]},
{"hex": "#f2d4cd", "rgb": [242, 212, 205]},
{"hex": "#755d7d", "rgb": [117, 93, 125]},
{"hex": "#e72c43", "rgb": [231, 44, 67]},
{"hex": "#5e274a", "rgb": [94, 39, 74]},
{"hex": "#e49097", "rgb": [228, 144, 151]},
{"hex": "#178e9a", "rgb": [23, 142, 154]},
{"hex": "#c93191", "rgb": [201, 49, 145]},
{"hex": "#ffa6e1", "rgb": [255, 166, 225]},
{"hex": "#1c1c2e", "rgb": [28, 28, 46]}
]
}

That’s it! Now you can find an accurate color palette from any image automatically through our web interface, fast huh? You can even combine this with our other microservices to do more complicated tasks, like extracting colors from all the images embedded in a webpage.

What if you want to extract even more information from images or even generate your own filters? Take a look at our implementations of Illustration2Vec, Deep Filter, Salnet, and Nudity Detection, for inspiration and tools to help build your next killer app!