Dear all, How to embed message bits in DWT coefficient values ?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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
Walter Roberson
on 12 Apr 2017
0 votes
Use an Integer Wavelet Transform (iwt)
8 Comments
Manashee Malita
on 13 Apr 2017
Edited: Manashee Malita
on 13 Apr 2017
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
Walter Roberson
on 13 Apr 2017
After you use the integer wavelet, use uint8() before you do the embedding.
Manashee Malita
on 16 Apr 2017
Thank you sir. It is working with Integer Wavelet Transform.
shimaa samy
on 5 May 2017
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
Walter Roberson
on 5 May 2017
Do not use dwt() at all. Use iwt() instead. The result will be integers that you can embed bits in.
shimaa samy
on 5 May 2017
Edited: Walter Roberson
on 6 May 2017
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?
shimaa samy
on 5 May 2017
Edited: Walter Roberson
on 6 May 2017
% 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
Walter Roberson
on 6 May 2017
You appear to have posted this question as https://www.mathworks.com/matlabcentral/answers/338974-help-embedding-secret-message-using-lwt-cannot-extract-the-secret-message-correctly
More Answers (0)
Categories
Find more on Denoising and Compression in Help Center and File Exchange
Products
See Also
on 12 Apr 2017
on 6 May 2017
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)