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.

 Akzeptierte Antwort

Guillaume
Guillaume am 24 Nov. 2014

0 Stimmen

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.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by