Dear all, How to embed message bits in DWT coefficient values ?

I wanted to embed some message bits in DWT coefficient values of an image and transmit. After embedding the message bits when I have performed uint8() to transmit the image as a grayscale image, at the receiving end, I am not able to get back the message bit from the same coefficient values. On the other hand, if I don't perform uint8() function, I can retrive the message bit successfully.

 Accepted Answer

8 Comments

Thank you sir, I have read these(which are in the link) but, not able to get my answer. My problem is that after embedding process, the image is reconstructed, but, the values are in double and when I convert it into uint8, some pixel values are also get changed which create a problem in retrieving the message in the receiving side. Thank you
After you use the integer wavelet, use uint8() before you do the embedding.
Thank you sir. It is working with Integer Wavelet Transform.
Hi, i am a beginner at image processing..i have the same problem after coverting to uint8 i cann't retrieve the hidden message.. i didn't get understand the solution of @Walter Roberson..when should i do the conversion and how?...plz i am a student and i need it so much..help me
Do not use dwt() at all. Use iwt() instead. The result will be integers that you can embed bits in.
first..thanks for your reply :)
yes i use lwt ..and it is also the same error..here is my code..i need your help so much..plz tell me what is wrong in my code
% reading the image
img=imread('c:\head4.tif');
% the row (the host row) in which i want to embed the secret message as an example at row
% 305 and start column 3 to end column 570
row_img=img(305,3:570);
% secret message is a vector
secret=[100,200,20,40,50,80,60,230,140,1,2,0,210,205,190,9,0,32,80,100,200,201,202,203,199,189,187,180,170,0,1,0,1,0,100];
secret_bin=dec2bin(secret,8);
secret_bin=secret_bin';
length_secret = size(secret_bin,1)*size(secret_bin,2);
wname = liftwave('haar','int2int');
host_row=double(row_img);
[CA, CD]=lwt(host_row,wname);
length_CA = size(CA,2);
c = 1;
% embedding the secret_bin in the last signficant bit of each CA ( 1 LSB of CA )
for b = 1:1:length_CA
if b <= length_secret
xb=CA(1,c);
if xb < 0
xb= abs(xb);
if strcmp(secret_bin(b), '0')
xb=bitset(xb,1,0);
else
xb=bitset(xb,1,1);
end
CA(1,c)=-xb;
else
if strcmp(secret_bin(b), '0')
CA(1,c) = bitset(CA(1,c),1,0);
else
CA(1,c) = bitset(CA(1,c),1,1);
end
end% end if xb<0
c = c+ 1;
if (c > length_CA)
c = 1;
end
end % if b <= length_secret
end % end for loop b=8:-1:1
stego_host_uint8 = uint8(ilwt(CA,CD,wname));
stego_host_dble = (ilwt(CA,CD,wname));
% Extracting the secret vector from the stego_host_uint8
watermarked_host=double(stego_host_uint8);
[CA_ex, CD_ex] = lwt(watermarked_host,wname);
length_CA_ex = size(CA_ex,2);
c = 1;
secret_bits_ex = zeros(1,size_data);
for b = 1:1:length_CA_ex
if b <= length_secret
xb=CA_ex(1,c);
if xb < 0
xb= abs(xb);
end
secret_bits_ex(b) = bitget(xb,1);
%letter = bitset(letter,b,bitget(xb,1));
c = c + 1;
end
end
% function i created
secret_ex=binRoundC2Dec(secret_bits_ex,8);
% comparison between the input secret vector and the extracted
message=secret';
if secret_ex == message
disp('yes equal');
else
disp('No Equal');
end
% the extracted output [100;200;20;40;114;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;162;0;1;0;1;0;100]
% the input secret [100;200;20;40;50;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;170;0;1;0;1;0;100]
% they are diffrent at positions 5 , 29 ...why?
% reading the image
img=imread('c:\head4.tif');
% the row (the host row) in which i want to embed the secret message as an example at row 305 and start column 3 to end column 570
row_img=img(305,3:570);
% secret message is a vector
secret=[100,200,20,40,50,80,60,230,140,1,2,0,210,205,190,9,0,32,80,100,200,201,202,203,199,189,187,180,170,0,1,0,1,0,100];
secret_bin=dec2bin(secret,8);
secret_bin=secret_bin';
length_secret = size(secret_bin,1)*size(secret_bin,2);
wname = liftwave('haar','int2int');
host_row=double(row_img);
[CA, CD]=lwt(host_row,wname);
length_CA = size(CA,2);
c = 1;
% embedding the secret_bin in the last signficant bit of each CA ( 1 LSB of CA )
for b = 1:1:length_CA
if b <= length_secret
xb=CA(1,c);
if xb < 0
xb= abs(xb);
if strcmp(secret_bin(b), '0')
xb=bitset(xb,1,0);
else
xb=bitset(xb,1,1);
end
CA(1,c)=-xb;
else
if strcmp(secret_bin(b), '0')
CA(1,c) = bitset(CA(1,c),1,0);
else
CA(1,c) = bitset(CA(1,c),1,1);
end
end% end if xb<0
c = c+ 1;
if (c > length_CA)
c = 1;
end
end % if b <= length_secret
end % end for loop b=8:-1:1
stego_host_uint8 = uint8(ilwt(CA,CD,wname));
stego_host_dble = (ilwt(CA,CD,wname));
% Extracting the secret vector from the stego_host_uint8
watermarked_host=double(stego_host_uint8);
[CA_ex, CD_ex] = lwt(watermarked_host,wname);
length_CA_ex = size(CA_ex,2);
c = 1;
secret_bits_ex = zeros(1,length_secret);
for b = 1:1:length_CA_ex
if b <= length_secret
xb=CA_ex(1,c);
if xb < 0
xb= abs(xb);
end
secret_bits_ex(b) = bitget(xb,1);
%letter = bitset(letter,b,bitget(xb,1));
c = c + 1;
end
end
% function i created
secret_ex=binRoundC2Dec(secret_bits_ex,8);
% comparison between the input secret vector and the extracted
message=secret';
if secret_ex == message
disp('yes equal');
else
disp('No Equal');
end
% the extracted output [100;200;20;40;114;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;162;0;1;0;1;0;100]
% the input secret [100;200;20;40;50;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;170;0;1;0;1;0;100]
% they are diffrent at positions 5 , 29 ...why?
% Extracting the secret vector from the stego_host_dble
watermarked_host_dbl=double(stego_host_dble);
[CA_ex_dbl, CD_ex_dbl] = lwt(watermarked_host_dbl,wname);
length_CA_ex = size(CA_ex_dbl,2);
c = 1;
secret_bits_ex_dbl = zeros(1,length_secret);
for b = 1:1:length_CA_ex
if b <= length_secret
xb=CA_ex_dbl(1,c);
if xb < 0
xb= abs(xb);
end
secret_bits_ex_dbl(b) = bitget(xb,1);
%letter = bitset(letter,b,bitget(xb,1));
c = c + 1;
end
end
% function i created
secret_ex_dbl=binRoundC2Dec(secret_bits_ex_dbl,8);
% comparison between the input secret vector and the extracted
message=secret';
if secret_ex_dbl == message
disp('yes equal from stego dble');
else
disp('No Equal from stego dble');
end
% the extracted output [100;200;20;40;50;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;170;0;1;0;1;0;100]
% the input secret [100;200;20;40;50;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;170;0;1;0;1;0;100]
% they are equal when extracting directly from double lwt without conversion to uint8

Sign in to comment.

More Answers (0)

Categories

Find more on Wavelet Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!