Scrambling pixels of an image

2 次查看(过去 30 天)
Hello,
I am trying to scramble the pixels of an image in order to hide it from others. I am using the following code:
in = imread('image.bmp');
[r, c] = size(in);
sOrder = randperm(r*c); % Order to scramble image
out = in(sOrder); % Scramble according to the scrambling order
First, I generate the the order of scrambling using randperm. Then, use this order to scramble the image.
Can someone please tell me how the line "out = in(sOrder)" works.
Thank you.

采纳的回答

Guillaume
Guillaume 2014-11-24
It is strange that you managed to write that code without understanding it.
When you do:
out = in([4 8 1 ...]);
The first value of out is the 4th value of in, the 2nd value of out is the 8th of in, the 3rd value of out is the 1st of in, etc.
Since sOrder is a random permutation of all the integers from 1 to the number of elements in in ( r*c which you could simply obtain with numel(in)), out is just a random permutation of all the elements of in.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by