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.

extract_secure.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function encode_t1(scaling,bias) %Embedding(winsize,sigma,scaling,bias)
clear all
% blksize=8;
% MaskSize=5;
% testimg='french-4';
load SecureResults\paras
ImIn = imread(['SecureResults\',testimg,'-wm-m',num2str(MaskSize),'.tif']);

[inRows, inCols]=size(ImIn);
RowsNum=double(floor(inRows/blksize));
ColsNum=double(floor(inCols/blksize));
Rows=blksize*RowsNum;
Cols=blksize*ColsNum;
Im0=zeros(Rows,Cols);%ignore rest if blocks don't fit well. Testing purpose only. Zero-padding in practice.
Im0=ImIn(1:Rows,1:Cols);

clear ImIn 

Im0=double(Im0);

%shift key generation
sblksize=blksize;%2^skwid;
sklen_row=ceil(Rows/sblksize);
sklen_col=ceil(Cols/sblksize);
sklen=skwid*(sklen_row+sklen_col);
load SecureResults\skey
if max(size(skey))~=sklen
    error('shift key sizes do not match!');
end
 
%2-D Shifting%%%%%%%%%%%%%%%%%%%
blkrows = 1:sblksize;
blkcols = blkrows;
srIm0=Im0;
%row shift first, shift to left side
for i=1:sklen_row
    this_rskey=skey(((i-1)*skwid+1):(i*skwid));
    this_rswid=num2str(this_rskey(1));
    for j=2:skwid
        this_rswid=[this_rswid,num2str(this_rskey(j))];
    end
    this_rswid=bin2dec(this_rswid);
    srIm0(((i-1)*sblksize+1):(i*sblksize),1:(Cols-this_rswid))=Im0(((i-1)*sblksize+1):(i*sblksize),(this_rswid+1):Cols);
    srIm0(((i-1)*sblksize+1):(i*sblksize),(Cols-this_rswid+1):Cols)=Im0(((i-1)*sblksize+1):(i*sblksize),1:this_rswid);
end
%Shift upwards.
s2Im0=srIm0;
for i=1:sklen_col
    this_cskey=skey(((sklen_row+i-1)*skwid+1):((sklen_row+i)*skwid));
    this_cswid=num2str(this_cskey(1));
    for j=2:skwid
        this_cswid=[this_cswid,num2str(this_cskey(j))];
    end
    this_cswid=bin2dec(this_cswid);
    s2Im0(1:(Rows-this_cswid),((i-1)*sblksize+1):(i*sblksize))=srIm0((this_cswid+1):Rows,((i-1)*sblksize+1):(i*sblksize));
    s2Im0((Rows-this_cswid+1):Rows,((i-1)*sblksize+1):(i*sblksize))=srIm0(1:this_cswid,((i-1)*sblksize+1):(i*sblksize));
end
%s2Im0 is the 2D shifted version in which the odd-even feature is used to embed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

nubn_blksize=mark_length(s2Im0,blksize,RowsNum,ColsNum,1);
disp(['There are ', num2str(nubn_blksize),' non-uniform ', num2str(blksize), 'x', num2str(blksize),' blocks out of ',num2str(RowsNum*ColsNum)]);

%calculate flipping scores (DRDM)
%im_scores=CalImDRDMs(Im0,MaskSize);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dataextracted=zeros(nubn_blksize,1);

blkrows = 1:blksize;
blkcols = blkrows;
k=0;
for i=0:(RowsNum-1)
    for j=0:(ColsNum-1)
        blk0=s2Im0(i*blksize+blkrows, j*blksize+blkcols);
        if max(max(blk0))~=min(min(blk0))
            k=k+1;
            sum_blk=sum(sum(blk0));
            dataextracted(k)=mod(sum_blk,2);            
        end
    end
end
save SecureResults\dataextracted dataextracted
disp('Data Hidden Extracted!');
load SecureResults\datahidden
diff=xor(datahidden,dataextracted);
error=sum(sum(diff));
disp(['Error in data extracted is ',num2str(error),' bits']);

fid=fopen(['SecureResults\',testimg,'-hiding_LOG-m',num2str(MaskSize),'.tex'],'a');
fprintf(fid,'\n\nDATA HIDDEN EXTRACTION:');
fprintf(fid,'\nThere are %d non-uniform  %d by %d, blocks out of %d blocks.',nubn_blksize,blksize,blksize,RowsNum*ColsNum);
fprintf(fid,'\nError in the hidden data extracted is %d bits.',error);
fclose(fid);

Contact us