Sunday, January 01, 2012

Art with Machine Learning

The other day my friend Nathan pointed me to the a Google+ post of Mohit Muthanna here.
Take all the pixels of a photograph, and rearrange them so that the final image looks like an artist's palette -- something to which you can take a paintbrush and recreate the original image.
Below is an example of an image he made, using k-means to cluster the pixels.
But why stop there? I decided to try going ahead and automatically paint the image with the palette. If you were to do this by painting every pixel with average color for its cluster, then this is just a form of  posterization (a cute way to do image compression).

Sierra Nevada CA

Instead I chose to use the original pixels, but to replace each pixel with a random pixel from the same cluster. The difference is admittedly subtle ... but it sometimes looks nice. Note that the pallet used to paint each picture is usually shown below it.



Sierra Nevada CA

I tried several non-random ways to paint the picture too, such as shifting pixels inside a given cluster


and sorting the pixels in each cluster by brightness (top to bottom).
Zurich

Below are a few more examples, 

NJIT Library

Sierra Nevada CA

Israel

England

Last Shuttle Launch

Calais

The code to do all this was written in Matlab, with the help of M. Chen's K-Means function. I'd be glad to give anyone the code, just email me.

No comments:

Post a Comment