Montagne, Informatique & Pensées...

Back to colors

publié le 02/04/2014
It took me (or more precisely my server) 2 full days to analyse 40 000 images (hiking photos) to extract the main colors and place them in the database. After so much work, I decided to do a little research for PHP color extracting libraries. I found three of them :

  1. Mine (ColorFinderPHP) (Did not have to search too long...)
  2. Color Extractor (License MIT)
  3. Colors of Image (License to be determined...)
Let's be objective and benchmark them all.

The benchmarking conditions

I set up a series of 16 small photos (120x90) from my server and decided to extract the main colors of these. Three aspects have been analysed :

  1. Ease of use and documentation
  2. Accuracy
  3. Efficiency
As for the rest, the code to test these libraries is so ugly that I will not include it here.

Ease of use

On this point, all three libraries are equal in their minimal (not to say limited) documentation. There may be additional features not listed but who knows...
Despite this, the code is easy enough to understand and what we want now is just a simple color analysis. In all cases, setting up the tests required 5 minutes per libraries on my part, even accounting for small modifications to me made to improve the libraries.


A most fluctuating notion ... In my opinion, such libraries should return the prominent color of an image as seen by a human being of normal constitution. Just to give an example :

On this image, the code should return two kinds of colors, the first being an nuance of green and the second a color between purple and pink.

Color Finder


Color Extractor


Colors of image


So Colors of image seems to lag behing on the accuracy aspect. In other cases, both Colors of image and Color Finder are wrong.
Concerning Color finder, the problems comes from the way it extracts the 3 colors, it requires the most used color based on hue then brightness then darkness. So if there are two bright colors that are prominent, then only one will be extracted.
Colors of image seems to make a good calculation but does not take into account the way humans see colors and so finds wrong results.


On this point, things are easier. Both Colors of image and Color Finder need almost 10 seconds to complete the extraction of colors from the 16 photos.
Color extraction, for his part, takes only 2.6 seconds to complete the same job.

And the winner is ...

Color extraction... The only drawback of this library is its relative lack of documentation. For all the other aspects, it is way in front of the others.
One of the features that are easily added to this library is the extraction of all colors with their relative weight in the image. It can be very usefull to compare two images that seem to contain the same colors.
php colors library

Pourquoi un blog ?

Il me fallait bien entrer dans la modernité, après tout, un développeur sans blog, c'est comme un trailer sans pipette ça fait pas sérieux.

Je ne suis pas sûr que ce blog fera sérieux mais, si lecteur il y a, ce sera à eux d'en décider.

Powered by Jalmot