how to make it short codes?
Afficher commentaires plus anciens
hi all.. if i have value of each block 8x8 pixels. i'm looking for how to random each block? any idea for it? but it's not effective. here's my codes.. could you fix it?
B=imread('filename');
a = reshape(B(1:128, 1:128), 8, 16, 8, 16);
a = permute(a, [1,3,2,4]);
%example for scramble positions
a(:,:,1,1)=a(:,:,16,2);
a(:,:,1,2)=a(:,:,2,1);
a(:,:,1,3)=a(:,:,4,1);
a(:,:,1,4)=a(:,:,6,1);
a(:,:,1,5)=a(:,:,7,4);
a(:,:,1,6)=a(:,:,9,16);
a(:,:,1,7)=a(:,:,5,10);
a(:,:,1,8)=a(:,:,7,1);
a(:,:,1,9)=a(:,:,5,1);
a(:,:,1,10)=a(:,:,5,1);
a(:,:,1,11)=a(:,:,4,4);
a(:,:,1,12)=a(:,:,3,1);
a(:,:,1,13)=a(:,:,2,3);
a(:,:,1,14)=a(:,:,2,5);
a(:,:,1,15)=a(:,:,5,4);
a(:,:,1,16)=a(:,:,15,2);
a(:,:,2,1)=...
a(:,:,..,..)=...
and so on until a(:,:,16,16). so we have 256 blocks to random without any change in the value of each block.
how to scramble it? i hope it'll easier
thanks..
Réponse acceptée
Plus de réponses (1)
Roger Stafford
le 25 Juil 2013
If I have understood your question correctly, you can keep the first three lines:
B = imread('filename');
a = reshape(B(1:128, 1:128), 8, 16, 8, 16);
a = permute(a, [1,3,2,4]);
Then do this:
p = bsxfun(@plus,64*randperm(256),(-63:0)'); % Calculate 16384 linear indices
a = reshape(a(p),8,8,16,16); % Permute the various 8 x 8 blocks in 'a'
(Note: Your method of operating on 'a' one 8 x 8 block at a time has the possibility of changing a block and then erroneously using those changed values to change another block instead of using its original values. To avoid this, you would have had to use a new variable temporarily and when finished, copy it back into 'a'. In any case, writing 256 lines of code would be rather tedious.)
1 commentaire
Tia
le 25 Juil 2013
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!