I try to write an algorithm that unscrambles images that were before scrambled by mixing up small blocks:
My idea is that in the bottom image there are more "sharp" corners compared to the image above. Therefore I try to minimize the functional:
energy(image) { score = 0; for(pixels inside the image) score = score + abs(pixel sum of sourrounding 4 pixels - 4 value of internal pixel) }
The energy should therefore be high if there are many hard edges and low for the original image. In a test I found that the original image has the score $845.812$ whereas the scrambled one has the score $1.085.521$ so the approach might be worth a try.
My question is whether there is an efficient method to minimize the energy function now without trying all $n!$ permutations (too many). Or a different approach I didn't come up with.