I tried this, and it worked for a few test pictures I downloaded, but it fails for the given Tokyo panorama: the dark edges and sharp corners in some buildings confuse the algorithm. The matching must be done on somewhat more than pixel values alone...
EDIT: See how my implementation fails: http://www.michielovertoom.com/incoming/TokyoPanoramaUnshred...
Re: your attempt: I think you just need to find the starting strip, looks like your algorithm is working.
The algorithm works fine for some random pictures I found on the web. It's just not working for the Tokyo picture ;-(
My algorithm, given a strip, would tell you which strip was on the right and also gave a certainty. The last strip would have a "next strip" value shared with an earlier strip (thus wrongly attached) but with less certainty.
Edit: Or (worst case) the last strip would have a high degree of uncertainty.
How do you calculate your certainty?
PS. Have you actually realized a succesful implementation? (Just curious)
http://webfuel.org/instaunshredderv2.php
It also works on the test images I created:
http://webfuel.org/a.png http://webfuel.org/b.png http://webfuel.org/c.png
My first take on it was the following: Take the average of the differences between each pixel and the pixel adjacent to it over each column and store that as, say, X[]. Find some maximum number such that the sum of every nth column of X - the sum of all other rows of X is maximised. That's the column width. Split into a series of columns, use stable matching to match columns based on the sum of differences between rightmost male pixel and leftmost female pixel over all rows. Use stable marrage to give you a partial ordering, turn into a complete ordering and unscramble the image.
Any better/more elegant solutions?