我想使用matlab使用matlab对图像进行加扰:
问题在于使用matlab中的circshift命令将第i行旋转Kr(i)量。此函数未使用特定行或列的索引。
%%Encryption till scrambled image
rgb = imread('image.jpg');
I=rgb2gray(rgb);
[w,h]=size(I);
imshow(I);
title('Original grayscale');
info = imfinfo('image.jpg');
bit=info.BitDepth;
range=(2^bit)-1;
Kc=randi(range,[1,h]); %generating a random array Kc of h
Kr=randi(range,[1,w]); %generating random array Kr
alpha=sum(I); %sum of all column element creating an linear array of h columns
alpha1=sum(I,2); %sum of all row element creating an linear array of w rows
M=mod(alpha,2); %linear array of h column
M1=mod(alpha1,2); %linear array of w rows
for i=1:h
if M(1:i)==0
I1=circshift(I(:,i),-Kc(i)); %shifts up
else
I1=circshift(I(:,i),Kc(i)); %shifts down
end
end
for j=1:w
if M1(j:1)==0
I2=circshift(I1(j,:),Kr(j)); %shifts right
else
I2=circshift(I1(j,:),-Kr(j)); %shifts left
end
end
figure
imshow(I2);
title('Scrambled Image');`