How can I pick a key colour in an image file in an automated way?
July 3, 2014 9:45 AM   Subscribe

Recently I am sure I saw a script or action that analysed an image file and instead of generating the average colour, looked for a key colour (for example a logo colour) and provided that colour value. For example it might look at this image and give you the blue or the pink rather than a beige / skin tone average. Does this sound familiar?
posted by stackhaus23 to Media & Arts (6 answers total) 1 user marked this as a favorite
 
This might do what you're asking: Colors Palette Generator
posted by royalsong at 10:22 AM on July 3, 2014


The Pantone app has the feature, but I don't know how reliably it works.
posted by beisny at 10:22 AM on July 3, 2014


You are looking to create a histogram of an image and then pick the most frequently occurring colour. There are lots of relevant scripts and tutorials for different programming languages floating around.

Here is one example that includes a downloadable PHP script if you wanted to do it on your own server.

Keep in mind that you might need to filter out the white from your results because logos often include lots of background so the "real" dominant colour (as understood by a human) may actually be the 2nd dominant colour.
posted by rada at 10:32 AM on July 3, 2014 [1 favorite]


Firefox contains code to extract the dominant color from a favicon. In addition to looking for the most common colors, it also buckets similar colors together and tries to ignore "background" colors (by looking at the corners, and trying to avoid "plain" colors like white or black).

You can check out the Java source code or also a JavaScript version with a similar (but not identical) algorithm. [Note: The JavaScript is written for use within Firefox, and won't work out of the box in other environments, but could be adapted with a small amount of work.]

This code is designed with small icons in mind, not photographs or large artworks.
posted by mbrubeck at 12:44 PM on July 3, 2014 [1 favorite]


More links:

An explanation of Chrome's favicon color extraction

The next version of Android will include a Palette class with methods to extract prominent colors from an image.
posted by mbrubeck at 1:50 PM on July 3, 2014


Response by poster: Thanks for all of the responses, I was hoping there might be a Photoshop batch plugin or similar that would do the trick. Some of these may well work though so will investigate further, many thanks.
posted by stackhaus23 at 6:44 AM on July 4, 2014


« Older Tips for Apartment Searching in SF   |   Plus-size snowflake seeks last-minute bridesmaid... Newer »
This thread is closed to new comments.