I am new to Matlab and tried embedding watermark and I did it successfully. Now, in Extraction, I am not getting it back properly.
function [ eximage ] = watermark_extract( Y,Y_ex )
host=double(Y);
ln = size(host,1); %the length of the image
hqln = ln/4; %the length of half of the middle quarter
% mqNo = (hqln/4)^2; %Number of middle quarter 8 x 8 squares
LU = ln/2-hqln+1; %the location of the left and upper side of the middle quarter
RL = ln/2+hqln; %the location of the right and lower side of the middle quarter
ex=double(Y_ex);
ln_ex = size(ex,1); %the length of the embedded image
hqln_ex = ln_ex/4; %the length of half of the middle quarter
% mqNo = (hqln/4)^2; %Number of middle quarter 8 x 8 squares
LU_ex = ln_ex/2-hqln+1; %the location of the left and upper side of the middle quarter
RL_ex = ln_ex/2+hqln;
counter = 0;
for s = LU:8:RL
for t= LU:8:RL
ho=host(s:s+7,t:t+7);
host1= blkproc(ho,[8,8],@dct2);%at location 5,2 dct 2 is applied to get the dct coefficients of host image
h(counter*4+1) = host1(5,2);
end
end
wm=[];
w=1; wm=ex;
for i = LU_ex:8:RL
for j= LU_ex:8:RL
d = ex(i:i+7,j:j+7); %
ex1 = blkproc(d,[8,8],@dct2); %at location 5,2 dct 2 is applied to get the dct coefficients of embedded or watermarked image
e(counter*4+1) = ex1(5,2);
end
end
alpha=0.02;
for rw=1:32
for co=1:32
if ne(ex1(5,2),host1(5,2))
wm(rw,co)=0;
else
wm(rw,co)=1;
end
end
end
eximage=blkproc(wm,[8 8],@idct2);% inverse of dct top get back the image
end
I embedded a watermark in locations 5,2 in the center of host image and applying a 32x32 binary image. What am I missing here?