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.

fhiding(testimg)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function encode_t1(scaling,bias) %Embedding(winsize,sigma,scaling,bias)
function fhiding(testimg)

blksize=8;
MaskSize=7;%5;

%testimg='ccitt4';%'french-4';
save HidingResults\paras blksize testimg MaskSize
clear all
load HidingResults\paras
WeiTable=WeiCal(MaskSize);
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);
nubn_blksize=mark_length(Im0,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) 
%No NEED to calculate ALL, SKIP UNIFORM BLOCKS
%im_scores=CalImDRDMs(Im0,MaskSize);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data2hide=rand(nubn_blksize,1);
data2hide=im2bw(data2hide);

Im_1=Im0;
blkrows = 1:blksize;
blkcols = blkrows;
k=0;
for i=0:(RowsNum-1)
    for j=0:(ColsNum-1)
        blk0=Im0(i*blksize+blkrows, j*blksize+blkcols);
        if max(max(blk0))~=min(min(blk0))          
            sum_blk=sum(sum(blk0));
            k=k+1;
            if mod(sum_blk,2)~=data2hide(k)
                this_blkrows=i*blksize+blkrows;
                this_blkcols=j*blksize+blkcols;
                blk_scores=CalImBlkDRDM(Im0,this_blkrows,this_blkcols,MaskSize,WeiTable,blksize);
                %blk_scores=im_scores(i*blksize+blkrows, j*blksize+blkcols);
                [MinRow,i1]=min(blk_scores);
                [RowMin,i2]=min(MinRow);
                row_No=i1(i2);
                col_No=i2;    
                blk0(row_No,col_No)=~blk0(row_No,col_No);
                %Problem: Confusion caused if after flipping, it becomes a uniform (all BLACK/WHITE) BLOCK
                if max(max(blk0))==min(min(blk0))
                    k=k-1;
                end
                Im_1(i*blksize+blkrows, j*blksize+blkcols)=blk0;
            end
        end
    end
end
truecapacity=k;
disp(['Amount of data hidden successfully is ',num2str(truecapacity),' bits']);
datahidden=data2hide(1:k);
save HidingResults\datahidden datahidden
imwrite(Im_1, ['HidingResults\',testimg,'-wm-m',num2str(MaskSize),'.tif']);
diffimg=xor(Im_1,Im0);
imwrite(diffimg,['HidingResults\',testimg,'-dif-m',num2str(MaskSize),'.tif']);
changednum=sum(sum(diffimg));
disp(['The number of changed pixels are ',num2str(changednum)]);
baseimg=0.8+Im0*0.2;
[diffm,diffn]=find(diffimg==1);
for i=1:changednum
    baseimg(diffm(i),diffn(i))=0;
end
imwrite(mat2gray(baseimg),['HidingResults\',testimg,'-supdif-m',num2str(MaskSize),'.tif']);

psnr_value=psnr(Im_1,double(Im0));
disp(['PNSR is ',num2str(psnr_value)]);
DRDM_value=CalDRDM(['test_images\',testimg,'.tif'],['HidingResults\',testimg,'-wm-m',num2str(MaskSize),'.tif'],5,nubn_blksize);
disp(['DRDM is ',num2str(DRDM_value)]);

fid=fopen(['HidingResults\',testimg,'-hiding_LOG-m',num2str(MaskSize),'.tex'],'w');
fprintf(fid,'Document Image Name: %s',testimg);
fprintf(fid,'\nImage is of size %d x %d, weight matrix size is %d',Rows, Cols,MaskSize);
fprintf(fid,'\nThere are %d non-uniform  %d by %d, blocks out of %d blocks.',nubn_blksize,blksize,blksize,RowsNum*ColsNum);
fprintf(fid,'\nAmount of data hidden successfully is %d bits',truecapacity);
fprintf(fid,'\nThe number of changed pixels are %d pixels',changednum);
fprintf(fid,'\nPNSR is %fdB',psnr_value);
fprintf(fid,'\nDRDM is %f with m = %d',DRDM_value,MaskSize);
fclose(fid);

extraction

Contact us