Please check my code of image steganography using LSB technique on egdes. It is giving an error which i am unable to find.
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Réponse acceptée
Arun Kumar
le 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
1 commentaire
Plus de réponses (1)
Ash Ch
le 17 Mar 2015
2 commentaires
Walter Roberson
le 3 Mai 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.
Voir également
Catégories
En savoir plus sur Encryption / Cryptography dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!