Given all the attention the internet has given to the colors of this dress, I thought it would be interesting to look at the capabilities for extracting colors in R.
R has a number of packages for importing images in various file formats, including PNG, JPG, TIFF, and BMP. (The readbitmap package works with all of these.) In each case, the result is a 3-dimensional R array containing a 2-D image layer for each of the color channels (for example red, green and blue for color images). You can then manipulate the array as ordinary data to extract color information. For example, Derek Jones used the readPNG function to extract data from published heatmaps when the source data has been lost.
Photographs typically contain thousands or even millions of unique colors, but a very human question is: what are the major colors in the image? In other words, what is the image's palette? This is a difficult question to answer, but Russell Dinnage used R's k-means clustering capabilities to extract the 3 (or 4 or 6 — you decide) most prominent colors from an image, without including almost-identical shades of the same color and filtering out low-saturation background colors (like gray shadows). Without any supervision, his script can easily extract 6 colors from this tail of this beautiful peacock spider. In fact, his script generates five representative palettes:
I used a similar process to extract the 3 major colors from "that dress":
So I guess it was black and blue after all! (Plus a heavy dose of white in the background)
Christophe Cariou used a similar palette-extraction process in R and applied it to every cover of Wired magazine since 1993. For each cover he extracted the 4 major colors, and then represented them all on this beautiful scatter diagram arranged on the color wheel:
You can see the individual colors for the last 58 Wired covers here.
The work on colour extraction I did was building on work by Jo-fai Chow here: http://blenditbayes.blogspot.co.uk/2014/05/towards-yet-another-r-colour-palette.html
And I contributed the code I wrote to his package rPlotter ( https://github.com/woobe/rPlotter ) for anyone who wants to try it themselves (not to mention a bunch of other useful functions for dealing with colours).
Posted by: Russell Dinnage | March 05, 2015 at 05:23