Today’s procrastination was learning how to divide a picture in color segments in R. I followed this awesome post by Ryan Walker on Color Quantization (original) and used one of the stormy pictures from Dubois from last post. Color quantization, according to wiki, is reducing the number of distinct colors in an image.
So, basically in order to reduce the number of colors, we use k-means clustering of the RGB chanels of the picture. At the end, we visualize the new color palette (with fewer colors) by using PCA to reduce the 3D RGB space into 2-dimensional space (U&V). The explanations in Ryan Walker’s post are better, so just go check it out for further details 🙂
Here is the original picture:
and that’s the 2-dimensional reduction of the original color space (representing >99% of the variation in the data):
And that’s what happens when we reduce the colors to 4, 6, 8, and 10:
Quite exciting! Now I could use this to analyse for example how fast grass is growing or drying, if I had multiple pictures, taken from the same location during the summer season. I guess the light should be the same too :). Probably won’t get to that, though. Too time consuming for a procrastination project.
I really wanted to know how to do simple things with pictures in R and this is my first time when I actually load a png image in R and play with it.
Few days ago I found this old but beautiful analysis of Flickr pictures by season and color. And while I was googling stuff about color analyses, I got to the post by Ryan Walker on Color Quantization. And that’s how I spent one hour instead of preparing my luggage for Vienna (PUB course) or working on my poster.