基于catmap的置乱算法

2019-04-15 13:12发布

基于catmap的置乱算法

*只能计算正方形图片
测试图片为200*200*3
*示例图片
catmap *code function test clc clear close all; pic = imread('1.jpg'); sub_h = 3; sub_w = 3; subplot(sub_h,sub_w,1); imshow(pic); title('原图'); pic_size = size(pic) assert(pic_size(1) == pic_size(2),'二位数组长度必须相等'); %pic_r = pic(:,:,1); %pic_g = pic(:,:,1); %pic_b = pic(:,:,1); a = [5,2,3;4,5,8;1,2,4;8,5,3]; b = [3,1,2;7,6,1;5,6,2;2,4,7]; %a(次数,通道数) count = 3;%次数 piccat(pic_size(1),pic_size(2),pic_size(3)) = 0; picdecat(pic_size(1),pic_size(2),pic_size(3)) = 0; pic_src = pic; for t = 1:count for c = 1:pic_size(3) %for c = 1:1 for x = 1 : pic_size(1) for y = 1:pic_size(2) catpos = [x,y] * [1 a(t,c);b(t,c) a(t,c)*b(t,c)+1]; cat_x = catpos(1); cat_y = catpos(2); while(cat_x > pic_size(1)) cat_x = cat_x - pic_size(1); end while(cat_y > pic_size(2)) cat_y = cat_y - pic_size(2); end piccat(cat_x,cat_y,c) = pic_src(x,y,c); %[t,x,y,c,cat_x,cat_y,pic(x,y,c)] end end end pic_src = uint8(piccat); subplot(sub_h,sub_w,t+sub_w); imshow(uint8(pic_src),[]); title(sprintf('加密%d次' ,t)); end subplot(sub_h,sub_w,2); imshow(uint8(piccat),[]); title('加密图'); pic_src = piccat; for t = 1:count for c = 1:pic_size(3) %for c = 1:1 for x = 1 : pic_size(1) for y = 1:pic_size(2) catpos = [x,y] * [1 a(count - t + 1,c);b(count - t + 1,c) a(count - t + 1,c)*b(count - t + 1,c)+1]; cat_x = catpos(1); cat_y = catpos(2); while(cat_x > pic_size(1)) cat_x = cat_x - pic_size(1); end while(cat_y > pic_size(2)) cat_y = cat_y - pic_size(2); end picdecat(x,y,c) = pic_src(cat_x,cat_y,c); %[t,x,y,c,cat_x,cat_y,pic(x,y,c)] end end end pic_src = uint8(picdecat); subplot(sub_h,sub_w,t+sub_w * 2); imshow(uint8(pic_src),[]); title(sprintf('解密%d次' ,t)); end subplot(sub_h,sub_w,3); imshow(uint8(picdecat),[]); title('解密'); end