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!


