Suppose your shuffled image is S. Then
temp = reshape(1:numel(S), size(S));
temp will be an array of linear indices -- temp(k) will be k.
Now apply your forward shuffling routine to temp, generating temp_mapped . Each value in temp_mapped will appear only once, and the location temp_mapped == k is the place that the shuffle maps pixel #k to. So you can undo it:
unshuffled = zeros(size(S), class(S));
unshuffled(temp_map) = S;
and you can cross-check by shuffling this and checking that you get out S.
By the way, once you have temp_mapped, you can use it to do all future shuffling,
S1 = unsuffled(temp_map);
S2 = S1(temp_map);
S3 = S2(temp_map);
and S3 would be unsuffled shuffled 3 times, without having to do any further computation of indices.
Best Answer