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 个评论
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