This is an example app, trying to mimic the iTunes cover colors algorithm.
It is a more or less direct port from Mathematica of the example code, provided by Seth Thompson.
- At first, the image is scaled down to max-width of 36px and max-height of 36 (to reduce the computation cost)
- A border of 1px around the image is removed, so that the new max. dimensions are 34x34.
The removal of the border is important, because some of the images have a fringy border (or just a normal border, too):
- A histogram of the 1px wide edge of the image is created and the most dominant color is selected
- A histogram of the complete image is created, which groups all (in the YUV color space) similar colors into buckets
- These buckets are sorted downwars.
- Now, from the top down two colors are searched, which are different enough from the background color
- If no two colors are found, then the background color is analyzed, whether it is a dark color (
luminance < 0.5
) and white is used (black otherwise).
This algorithm (and implementation!) is not optimal in many cases:
Example: the bow tie of Aloe Blacc is not recognized:
Currently, the text colors are chosen, so that there is a large enough (to be defined) color difference between the colors. This can lead to potentialy low contrast, especially if you use the colors without any separation.
Example: Adele - 21
This implementation was created in just 3 hours, so there might be bugs or places for optimizations included. :-)
- Original by Seth Thompson
- One of the many implementations of Seth Thompson's algorithm in JavaScript
- The YUV color space details (esp. translation RGB -> YUV)
- An implementation in Objective-C with some differences
- An other approach using R-Trees
- Yet another approach using k-means clustering
The rights of all used cover images lie with the appropriate copyright owners.