首先把图片打散成8x8的像素组块,然后乱序组成与原图一样大小的无意义图形后导出,请问用MATLAB怎么实现
map = imread('girl.jpg');
subplot(121);
imshow(map);
dim = size(map);
m = dim(1);
m1 = (m-mod(m,8))/8;
n = dim(2);
n1 = (n-mod(n,8))/8;
map1 = imresize(map,[m1*8 n1*8]);
array = randperm(64);
array = reshape(array,8,8);
map2 = map1;
for i = 1:8
for j = 1:8
array0 = array(i,j);
j1 = mod(array0,8);
if j1 == 0
j1 = 8;
end
i1 = (array0-j1)/8+1;
map2(m1*(i-1)+1:m1*i,n1*(j-1)+1:n1*j,:) = map1(m1*(i1-1)+1:m1*i1,n1*(j1-1)+1:n1*j1,:);
end
end
map3 = imresize(map2,[m n]);
subplot(122);
imshow(map3);
代码可行,十分感谢,那么最后一个问题,我实际上只需要那个新图,请问怎么导出,我是个小白试了很久。。。可不可以直接在代码哪里,把新图另存为一下,请帮忙加两行代码实现 谢谢
clf
imshow(map3);
saveas(gcf,'result','jpg');