Clear Filters
Clear Filters

Scrambling pixels of an image

2 views (last 30 days)
Anisha Coelho
Anisha Coelho on 24 Nov 2014
Answered: Guillaume on 24 Nov 2014
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.

Accepted Answer

Guillaume
Guillaume on 24 Nov 2014
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!