A couple of weeks ago Instagram wrote a blog post about taking an image that has been shredded into slices and rearranging the slices to reconstruct the original image.
I wrote up a solution in coffeescript that I'd like to share. It's quite effecitve and the implementation is fairly simple. We treat each edge of the shreds as a signal, we correlate them using the Pearson product-moment correlation coefficient, and then use a simple traveling salesman algorithm to find the best arrangement of shreds.
Rather than interweave a whole bunch of code and text in this post, I thought I'd try using Jashkenas' annotated source code tool called docco and see how that works.
And of course, here's a demo with five images to try.
Two quick disclaimers: I've only tested the demo in Chrome, and it may take a minute or two to run on slower comptuers.
About the author
I'm Steve Krenzel, a software engineer and co-founder of Thinkfuse. Contact me at firstname.lastname@example.org.