can i get a matlab code for embedding secret image in the cover image using LSB method?

In my paper i have generated huffman encoded bitstream for secret image by applying huffman encoding & it is decomposed into 3 bit blocks thus forms a decimal value ranging from 0 to 7 For eg.110 001 010 111 100 000 011 then i decomposed the cover image by using haar wavelet transform.I selected HH band for embedding secret message, the 3 LSB of wavelet coefficients is replaced by the 3 bits of huffman encoded bitstream in the form of 3 bit block. i completed my work till this..!
The problem is the embedded output is not identical to the original image. plz help me to locate the error and help me with the corrected code.
% Image to be Encoded
inputimg = imread('emblem.png');imview('emblem.png');
vecImg = reshape(inputimg,1,[]);
Data = vecImg;
% Perform Huffman Encoding
HEAD=0;
%%%%%%%%%%%%%%%%%%%%
%--Compute Header--------
POS=0;
S_=size(Data);
for i=1:S_(2)
if (POS~=0)
S=size(HEAD); F=0;
k=1;
while (F==0 && k<=S(2))
if (Data(i)==HEAD(k)) F=1; end;
k=k+1;
end;
else F=0;
end;
if (F==0)
POS=POS+1;
HEAD(POS)=Data(i);
end;
end;
fprintf('Header:\n');
display(HEAD);
%%%%%%%%Compute probability for symbols%%%%%%%%%%%%
S_H=size(HEAD);
Count(1:S_H(2))=0;
for i=1:S_H(2)
for j=1:S_(2)
if (Data(j)==HEAD(i))
Count(i)=Count(i)+1;
end;
end;
end;
Count=Count./S_(2);
fprintf('probability for symbols\n');
display(Count);
%%%Sort accoridng to maximum number%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:S_H(2)-1
for j=i+1:S_H(2)
if (Count(j)>Count(i))
T1=Count(i); Count(i)=Count(j); Count(j)=T1;
T1=HEAD(i); HEAD(i)=HEAD(j); HEAD(j)=T1;
end;
end;
end;
fprintf('Sort Results\n');
display(HEAD);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[dict,avglen] = huffmandict(HEAD,Count); % Create dictionary.
hcode = huffmanenco(Data,dict); % Encode the data.
display (hcode);
%Cover Image
img = imread('pepper.jpg');imview('pepper.jpg');
sX=size(img);
% Discrete Wavelet Transform
[LL LH HL HH]=dwt2(img,'haar');
dec=[...
LL,LH
HL,HH
...
];
figure;imshow(dec,[]);title ('DWT');
%Embedding Image in 3 X 3 bit Propagation
% Selected Band is HH.
b = 3;
txt = hcode;
I = HH;
N = 8*numel(txt);
S = numel(I);
if N > S
warning('Content Truncated')
txt = txt(1:floor(S/8));
N = 8*numel(txt);
end
p = 2^b;
h = 2^(b-1);
I1 = reshape(I,1,S);
addl = S-N;
dim = size(I);
I2 = round(abs(I1(1:N)));
si = sign(I1(1:N));
for k = 1:N
if si(k) == 0
si(k) = 1;
end
I2(k) = round(I2(k));
if mod((I2(k)),p) >= h
I2(k) = I2(k) - h;
end
end
bt = dec2bin(txt,8);
bint = reshape(bt,1,N);
d = h*48;
bi = (h*bint) - d;
I3 = double(I2) + bi;
binadd = [bi zeros(1,addl)];
I4 = double(si).*double(I3);
I5 = [I4 I1(N+1:S)];
img = reshape(I5,dim);
%img = embedAction(double(HH),hcode,3);
%Perform Inverse Wavelet Transform
X = idwt2(img,LH,HL,HH,'haar',sX);
figure;imshow(uint8(X));title('IDWT');
% Writing Embedded Image file
imwrite(uint8(X),'embed.jpg','jpg');
figure;
imshow(uint8(X));title('EMBEDDED OUTPUT');
Thanks in advance..!

 Accepted Answer

The embedded output WON'T be identical to the input image. Why do you think it should be? You hid a secret image in it so of course it's different.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!