Code covered by the BSD License  

Highlights from
Binary Image Watermarking/Data Hiding: Data, Algorithms, and Distortion Measure

Binary Image Watermarking/Data Hiding: Data, Algorithms, and Distortion Measure

by

 

26 Apr 2012 (Updated )

A package on binary image watermarking/data hiding, including data, algorithms & distortion measure.

fextract.m
clear all 
load Results\ecc
load Results\paras
load Results\key key
embedpara=['_e_',num2str(ecc_col),'_f_',num2str(maxflip)];
ImIn = imread(['Results\',testimg,'-wm',embedpara,'.tif']);
[inRows, inCols]=size(ImIn);
RowsNum=double(floor(inRows/blksize));
ColsNum=double(floor(inCols/blksize));
Rows=blksize*RowsNum;
Cols=blksize*ColsNum;
Im_1=zeros(Rows,Cols);%ignore rest if blocks don't fit well. Testing purpose only. Zero-padding in practice.
Im_1=ImIn(1:Rows,1:Cols);

clear ImIn 

Im_1=double(Im_1);

% Im_1pp=ones(Rows+6,Cols+6);
% Im_1pp(4:(Rows+3),4:(Cols+3))=Im_1;
% h = fspecial('gaussian',5,1);
% FIm_1=FIm_1pp(4:(Rows+3),4:(Cols+3));

wm_2extract=zeros(RowsNum*ColsNum,1);

blkrows = 1:blksize;
blkcols = blkrows;
wk=0;
kk=0;
for i=0:(RowsNum-1)
    for j=0:(ColsNum-1)
        kk=kk+1;
        if key(kk)~=0
            blk_im1=Im_1(i*8+blkrows, j*8+blkcols);
            testdc=sum(sum(blk_im1));
            wk=wk+1;
            if testdc>key(kk)
                wm_2extract(wk)=1;  %fail if blkdct_wm(1,1)/blkdct0(1,1);
            end            
        end
    end
end

codeword_num=floor(wk/ecc_n);
wm_len=codeword_num*ecc_k;
wmecc_len=codeword_num*ecc_n;
dataextracted=wm_2extract(1:wmecc_len);
wmdecoded = decode(dataextracted,ecc_n,ecc_k,'bch/binary');
save Results\dataextracted dataextracted wmdecoded
disp('Data Hidden Extracted!');
load Results\datahidden
diff_data=xor(data2hide,dataextracted);
diff_wm=xor(wmb4ecc,wmdecoded);
error_wm=sum(sum(diff_wm));
error_data=sum(sum(diff_data));
disp(['Error in ECC data extracted is ',num2str(error_data),' bits']);
disp(['Error in decoded watermark is ',num2str(error_wm),' bits']);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% corrs=zeros(1,1000);
% for i=1:1000
%    corrs(i)=corr2(dataextracted,randn(wk,1));
% end
% corrs(500)=corr2(datahidden,dataextracted);
% disp(['Correlation is ',num2str(corrs(500))]);
% 
% x=1:1000;
% plot(x,corrs)
% set(gca,'FontSize',20);
% grid on
% title(['Correlation=',num2str(corrs(500))],'FontSize',20);
% xlabel('True and False Watermarks','FontSize',20);
% ylabel('Detector Response','FontSize',20);
% print(1,'-dpng','-r90',['Results\detection.png']);
% delete(1);

fid=fopen(['Results\',testimg,'-LOG',embedpara,'.tex'],'a');
fprintf(fid,'\n\nDATA HIDDEN EXTRACTION:');
fprintf(fid,'\nError in the ECC data extracted is %d bits.',error_data);
fprintf(fid,'\nError in the decoded watermark is %d bits.',error_wm);
%fprintf(fid,'\nThe correlation of ECC data is %f.',corrs(500));
fclose(fid);

Contact us