MATLAB Answers

TJ Singh
0

digital image watermarking. using DWT

Asked by TJ Singh
on 24 Mar 2012
Latest activity Commented on by SWATI MISHRA
on 10 Mar 2016

I'm working in digital image watermarking. I've found DWT matlab code on internet, but it can't give proper results. plz debug it, so that it works properly.

% Watermark Embeding
clear all;
 % save start time
start_time=cputime;
 k=2;            % set the gain factor for embeding
 % read in the cover object
file_name='_lena_std_bw.bmp';
cover_object=double(imread(file_name));
 % determine size of watermarked image
Mc=size(cover_object,1);    %Height
Nc=size(cover_object,2);    %Width
 % read in the message image and reshape it into a vector
file_name='_copyright.bmp';
message=double(imread(file_name));
Mm=size(message,1);                         %Height
Nm=size(message,2);                         %Width
message_vector=round(reshape(message,Mm*Nm,1)./256);
[cA1,cH1,cV1,cD1] = dwt2(cover_object,'haar');
 % add pn sequences to H1 and V1 componants when message = 0 
for (kk=1:length(message_vector))
    pn_sequence_h=round(2*(rand(Mc/2,Nc/2)-0.5));
    pn_sequence_v=round(2*(rand(Mc/2,Nc/2)-0.5));
       if (message(kk) == 0)
        cH1=cH1+k*pn_sequence_h;
        cV1=cV1+k*pn_sequence_v;
    end
end
 % perform IDWT
watermarked_image = idwt2(cA1,cH1,cV1,cD1,'haar',[Mc,Nc]); 
 % convert back to uint8
watermarked_image_uint8=uint8(watermarked_image);
 % write watermarked Image to file
imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp');
 % display processing time
elapsed_time=cputime-start_time,
% display watermarked image
figure(1)
imshow(watermarked_image_uint8,[])
title('Watermarked Image')
% Watermark Recovery
clear all;
% save start time
start_time=cputime;
% read in the watermarked object
file_name='dwt_watermarked.bmp';
watermarked_image=double(imread(file_name));
% determine size of watermarked image
Mw=size(watermarked_image,1);           %Height
Nw=size(watermarked_image,2);           %Width
% read in original watermark
file_name='_copyright.bmp';
orig_watermark=double(imread(file_name));
% determine size of original watermark
Mo=size(orig_watermark,1);  %Height
No=size(orig_watermark,2);  %Width
 % initalize message to all ones
message_vector=ones(1,Mo*No);
 [cA1,cH1,cV1,cD1] = dwt2(watermarked_image,'haar');
 % add pn sequences to H1 and V1 componants when message = 0 
for (kk=1:length(message_vector))
    pn_sequence_h=round(2*(rand(Mw/2,Nw/2)-0.5));
    pn_sequence_v=round(2*(rand(Mw/2,Nw/2)-0.5));
       correlation_h(kk)=corr2(cH1,pn_sequence_h);
    correlation_v(kk)=corr2(cV1,pn_sequence_v);
    correlation(kk)=(correlation_h(kk)+correlation_v(kk))/2;
end
 for (kk=1:length(message_vector))
    if (correlation(kk) > mean(correlation))
        message_vector(kk)=0;
    end
end
 % reshape the message vector and display recovered watermark.
figure(2)
message=reshape(message_vector,Mo,No);
imshow(message,[])
title('Recovered Watermark')
 % display processing time
elapsed_time=cputime-start_time,

  1 Comment

If u have any query thn regarding ur project either mail at matlabprojects35@gmail.com or, https://www.facebook.com/MatlabProjects-909644652486619. Kindly Spread it to Help Others.

2 Answers


please mail me the code in the form of .m exactly, so that i can work out and will let you know.

Regards, Siva siva@sdatech.in

  4 Comments

madhuri
on 13 Apr 2012

hi
im also gtting difficulty in running these codes.
Do u have some relevant hybrid watermarking code that i can refer for my thesis work??if so plz mail me at engr.madhuri@gmail.com

Do help me.

Fatima
on 17 May 2013

hi

I'm also getting difficulty in running these codes.

please, can you mail me the code at: fatimaezzahra.it@gmail.com

thank you.

I need code for digital watermarking using DWT algorithm.Can you please send the MATLAB code.It is very important and urgent as well.Send me code at swatiimishra1@outlook.com


Answer by Afroja Akter
on 30 Jul 2013

could u give any code for evalution purpose like NC(NORMALISED CORRELATION),,also could u tell me why not i could not save ma image wchich has been embedded,,

  2 Comments

im aslo getting errors while running could you plz tell me tha correct code by taking an example image

If u have any query thn regarding ur project either mail at matlabprojects35@gmail.com or, https://www.facebook.com/MatlabProjects-909644652486619


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!