loop for image encryption gives error
显示 更早的评论
I am using 8*8 matrix for image encryption but there is an error in loop which i cannot figure out why.
Km=[K11 K12;K21 K22];% 8 cross 8 matrix
I=imread('lena256.jpg');
imshow(I);
[X Y]=size(I);
for i=1:X
for j=1:4:Y
P=double(I(i,j:j+3));
EncImg(i,j:j+3)=mod((Km*P')',256);
end
error is in EncImg(i,j:j+3)=mod((Km*P')',256))
7 个评论
sadiqa ilyas
2019-7-31
darova
2019-7-31
index exceeds matrix dimensions
for j=1:4:Y % when j == Y
P=double(I(i,j:j+3)); % you are trying to get access to I(i,Y:Y+3)
Walter Roberson
2019-7-31
I suspect that your image is rgb and that you are misusing size()
sadiqa ilyas
2019-7-31
sadiqa ilyas
2019-7-31
darova
2019-7-31
What did you change to get rid of it?
Walter Roberson
2019-7-31
Most jpg images are rgb even when they look gray. Real grayscale jpg images are rare. You should always check ndims of a jpg image and rgb2gray if it is not 2.
采纳的回答
更多回答(1 个)
sadiqa ilyas
2019-8-1
4 个评论
Walter Roberson
2019-8-1
I1 is a 3D array because it is RGB. You are passing it to SBox(). We do not know what SBox does with it, but likely SBox is also returning a 3D array (RGB). Then you take size() in exactly the way I told you twice before was wrong.
[X, Y]=size(I2);
will not, I repeat not return the number of rows into X, and the number of columns into Y when I2 is an RGB array: it would instead return the number of rows into X, and the number of color panes (i.e., 3) times the number of columns into Y.
You then proceed to try to encrypt the RGB image into a 2D array instead of encrypting it into a 3D array as would be needed for RGB.
sadiqa ilyas
2019-8-1
Walter Roberson
2019-8-1
This is getting close to the point where I have to stop you and say that we cannot help you any further. Due to the laws of the USA, we can effectively only discuss encryption here as long as your program is pretty broken, to the point where someone else would have trouble using the code to implement a working encryption function. When we start getting to the point where there is a chance that your program might start working, we cannot assist you further and we cannot permit you to post code that is nearly working.
The laws of the USA about this might not be wise or convenient, but we have to live with them.
sadiqa ilyas
2019-8-1
类别
在 帮助中心 和 File Exchange 中查找有关 Texture Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


