clear
RGB=imread('2.png');
s=size(RGB);
i=randsample(s(2),s(2));
l=length(i);
RGBS=RGB(:,i,:);
t=1;j=1;f=1:i;
for t=1:l
f(j)=find(i==t);
t=t+1;
j=j+1;
end
f;
RGBE=RGBS(:,f,:);
imshow(RGB);title('原图','fontsize',26);
figure;
subplot(1,2,1);imshow(RGBS);
title('加密图像','fontsize',23);
subplot(1,2,2);imshow(RGBE);
title('解密图像','fontsize',23);
本程序摘自《MATLAB仿真及其在光学课程中的应用》一书第六章