Please check my code of image steganography using LSB technique on egdes. It is giving an error which i am unable to find.

조회 수: 3 (최근 30일)
a=imread('Lenna.png');
b=rgb2gray(a);
edge_b=edge(b,'sobel');
imshow(edge_b);
message = 'hello lenna'
message = strtrim(message);
m = length(message) * 8;
AsciiCode = uint8(message);
binaryString = transpose(dec2bin(AsciiCode,8));
bst = binaryString(:);
N = length(bst);
z = zeros(N,1);
for k = 1:N
if(bst(k) == '1')
z(k) = 1;
else
z(k) = 0;
end
end
height = size(b,1);
width = size(b,2);
k1=m;
while k1>0,
for i=1:height-1
for j=1:width-1
if edge_b(i,j)==1
lsb=mod(b(i,j),2);
if (lsb == z(k1))
b(i,j) = b(i,j);
else
if(lsb == 1)
b(i,j) = b(i,j) - 1;
else
b(i,j) = b(i,j) + 1;
end
end
k1 = k1 - 1;
end
end
end
end
error: ??? Attempted to access z(0); index must be a positive integer or logical.

채택된 답변

Arun Kumar
Arun Kumar 2015년 3월 17일
there is no need for while loop.
for i=1:height-1
for j=1:width-1
if k1>0
if edge_b(i,j)==1
lsb=mod(b(i,j),2);
if (lsb == z(k1))
b(i,j) = b(i,j);
else
if(lsb == 1)
b(i,j) = b(i,j) - 1;
else
b(i,j) = b(i,j) + 1;
end
end
k1 = k1 - 1;
end
end
end
end

추가 답변 (1개)

Ash Ch
Ash Ch 2015년 3월 17일
You are GOD. Thank you so much. The code finally ran after decades. But can you please tell me why 'while' didn't work?
  댓글 수: 2
eng
eng 2015년 7월 3일
plz. where is the decoding code ? can you continue it from your kind ?
Walter Roberson
Walter Roberson 2019년 5월 3일
You initialize k1 as m, length of the message times 8. You decrement k1 each time you encounter an edge pixel and you access z(k1). If the number of edge pixels exceeds m then you decrement k1 right down to 0 in the for loops.
In the original code if the number of edge pixels is less than the message length then your k1 will be positive after the nested for loops and the while would trigger another pass of placing bits where they were already placed. This could happen several times. Eventually you hit a pass where there are fewer bits remaining to be placed than there are edge bits.
The original cide only works properly in the case where the number of edge bits happens to be exactly the same as the number of message bits.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by