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.

[Erec_crop,Erwm_crop]=cropone(Im0_2,ImWmed,linescrop)
function [Erec_crop,Erwm_crop]=cropone(Im0_2,ImWmed,linescrop)

%clear all 
load Results\ecc
load Results\paras
load Results\key key
%ImIn = imread(['Results\',testimg,'-wm','.tif']);
ImIn=Im0_2;
%Im_wm(1:linescrop,:)=ImWmed(1:linescrop,:);
ImIn((512-linescrop+1):512,:)=ImWmed((512-linescrop+1):512,:);

[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);
Erwm_crop=sum(sum(diff_wm))/max(size(wmdecoded));
Erec_crop=sum(sum(diff_data))/max(size(data2hide));

Contact us