Project Nayuki

Image unshredder by annealing

Live demo (JavaScript)

, CC license
Current iterations:
Current temperature:
Current energy:


On another page, I unleash the simulated annealing algorithm on a toy problem. It generates an image full of random colorful pixels, and rearranges the pixels so that similar colors are near each other.

Here I try to solve a more realistic problem. Suppose we took an ordinary image and scrambled it by rearranging the columns of pixels. This would be like shredding the image into vertical strips and shuffling them. Can we use simulated annealing to unscramble the image automatically without relying on human intelligence? The answer, pleasantly enough, is yes.

To operate this JavaScript demo, first choose an image or proceed with the default one. Next press the “Shuffle” button. Then check the settings for simulated annealing (the defaults are a good starting point), and press the “Anneal” button. Note that after shuffling, you anneal any number of times, and the annealing will start from the shuffled state (not from the most recently annealed state).

Source code


The JavaScript version of the program is what powers this web page. The Java version of the annealer is much faster than the JavaScript version (about 4× faster on my machine), the code is cleaner, and it is suitable for headless and batch processing.