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.

fhidingSecure_study.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%fhidingSecure_study
clear all
load SecureResults\paras
ImIn = imread(['test_images\',testimg,'.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
load SecureResults\skey 
sblksize=blksize;%2^skwid;
sklen_row=ceil(Rows/sblksize);
sklen_col=ceil(Cols/sblksize);
sklen=skwid*(sklen_row+sklen_col);
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

blkrows = 1:blksize;
blkcols = blkrows;
spbn=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))          
            sum_blk=sum(sum(blk0));
            if sum_blk==1 || sum_blk==(blksize^2-1);
                spbn=spbn+1;                
            end
        end
    end
end
disp(['The number of single pixel blocks are ',num2str(spbn)]);
fid=fopen(['SecureResults\',testimg,'-hiding_LOG-m',num2str(MaskSize),'.tex'],'a');
fprintf(fid,'\nThere are %d singlediff pixel  %d by %d, blocks out of %d blocks.',spbn,blksize,blksize,RowsNum*ColsNum);
fclose(fid);

Contact us