我更喜欢Lena
,所以我们开始-
%// Indices of specific blocks to be randomized
sp_idx = [2,2;2,3;2,4;2,5;2,6;3,2;3,3;3,4;3,5;3,6;4,2;4,3;4,4;4,5;4,6;
5,3;5,4;5,5;6,3;6,4;6,5;7,3;7,4;7,5];
%// Invite lena to MATLAB workspace and *cut off her right arm*
im = imread('http://www.ece.rice.edu/~wakin/images/lenaTest3.jpg');
im = im(:,1:448);
%// Define blocksize (rows x columns)
n = 64;
m = 64;
%// New random indices corresponding to sp_idx
new_rand_idx = sp_idx(randperm(size(sp_idx,1)),:);
%// Split image into blocks
split_blks = mat2cell(im, ones(1,8)*n, ones(1,7)*m);
%// Get old and new linear indices and thus randomize specific blocks
old_lind = sub2ind(size(split_blks),sp_idx(:,1),sp_idx(:,2));
new_lind = sub2ind(size(split_blks),new_rand_idx(:,1),new_rand_idx(:,2));
split_blks(new_lind) = split_blks(old_lind);
new_im = cell2mat(split_blks);
%// Show images
figure,
subplot(121),imshow(im),title('Before')
subplot(122),imshow(new_im),title('After')
输出 -
