A python implementation of this idea: http://imgur.com/gallery/ld1ibXC