Please check my code of image steganography using LSB technique on egdes. It is giving an error which i am unable to find.
3 views (last 30 days)
Show older comments
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.
1 Comment
Accepted Answer
Arun Kumar
on 17 Mar 2015
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
More Answers (1)
Ash Ch
on 17 Mar 2015
2 Comments
Walter Roberson
on 3 May 2019
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.
See Also
Categories
Find more on Encryption / Cryptography in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!