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.

study_distri.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all

blksize=8;
testimg='french-4';%'ccitt4';%'french-4';
% MaskSizes=[3,5,7,11,15];
% slines=['-o','-*','-x','-s','-d'];
testmnum=3;
MaskSizes=[3,7,11];
slines=[':k','-k','-.'];
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)]);

flipT=0.5;
fid=fopen(['StudyResults','\',testimg,'-LT',num2str(flipT),'-m',num2str(MaskSizes(1)),'-',num2str(MaskSizes(testmnum)),'.xls'],'w');
fprintf(fid,'Document Image Name: %s',testimg);
fprintf(fid,'\nImage is of size %d x %d',Rows, Cols);
fprintf(fid,'\nThere are %d non-uniform  %d by %d, blocks out of %d blocks.',nubn_blksize,blksize,blksize,RowsNum*ColsNum); 
fprintf(fid,'\nMaskSize\tmax_min\tNUBN_DRDM_std_av\tNUBN_DRDM_mean_av\tLT%.2fNum_av\tLT%.2fNum_min',flipT,flipT);

%calculate flipping scores (DRDM) 
%No NEED to calculate ALL, SKIP UNIFORM BLOCKS
%im_scores=CalImDRDMs(Im0,MaskSize);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
blkrows = 1:blksize;
blkcols = blkrows;
figure
hold on
grid on
for m=1:testmnum
    disp(['current loop: m = ',num2str(m)]);
    WeiTable=WeiCal(MaskSizes(m));
    %calculate flipping scores (DRDM) 
    %     im_scores=CalImDRDMs(Im0,MaskSizes(m));
    %     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %     imhist(im_scores);
    %     imtitle=['Distribution of DRDM scores for m = ',num2str(MaskSizes(m)),' in ',testimg];
    %     title(imtitle);
    %     print(1,'-dpng','-r90',['DistGraph','\',ImName,'m-',num2str(MaskSizes(m))]);
    %     delete(1);
    %     distinct_whole=diff_num(im_scores); %This number ==27 for m=3 for french-4.tif
    %     fprintf(fid,'\n%d\tDistinctWhole\tDistinctNUBN');       
    DRDM_std_sum=0;  
    DRDM_mean_sum=0;
    LTp5_num_sum=0;
    LTp5_num_min=blksize^2;
    LTp5_num_record=zeros(1,blksize^2+1);
    max_mins=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))                      
                this_blkrows=i*blksize+blkrows;
                this_blkcols=j*blksize+blkcols;
                blk_scores=CalImBlkDRDM(Im0,this_blkrows,this_blkcols,MaskSizes(m),WeiTable,blksize);
                [MinRow,i1]=min(blk_scores);
                [RowMin,i2]=min(MinRow);
                row_No=i1(i2);
                col_No=i2;    
                if blk_scores(row_No,col_No)>max_mins
                    max_mins=blk_scores(row_No,col_No);
                end
                DRDM_std_sum=DRDM_std_sum+std(blk_scores(:));
                DRDM_mean_sum=DRDM_mean_sum+mean(blk_scores(:));
                [LTp5m,LTp5n]=find(blk_scores<flipT);                
                LTp5_num=max(size(LTp5m));
                LTp5_num_record(LTp5_num+1)=LTp5_num_record(LTp5_num+1)+1;
                LTp5_num_sum=LTp5_num_sum+LTp5_num;
                if LTp5_num<LTp5_num_min
                    LTp5_num_min=LTp5_num;
                end                
            end
        end
    end   
    DRDM_std=DRDM_std_sum/nubn_blksize;  
    DRDM_mean=DRDM_mean_sum/nubn_blksize;
    LTp5_num=LTp5_num_sum/nubn_blksize;
    x_axis=0:64;
    %    plot(x_axis,LTp5_num_record/nubn_blksize,slines(m));
    plot(x_axis,LTp5_num_record/nubn_blksize,slines((2*m-1):(2*m)),'LineWidth',3);
    fprintf(fid,'\n%d\t%.3f\t%.3f\t%.3f\t%.3f\t%d',MaskSizes(m),max_mins,DRDM_std,DRDM_mean,LTp5_num,LTp5_num_min);    
end
set(gca,'FontSize',16);
%imtitle=['NUBN blks (%) Vs pixels (#) with DRDM<',num2str(flipT),' in ',testimg];    
imtitle=['Pixels with DRDM<',num2str(flipT),' in ',testimg];    
xlabel(['pixel number with DRDM<',num2str(flipT),' in ',testimg]);
ylabel(['Percentage of Non-Uniform Blocks']);
title(imtitle);
%legend(['m=',num2str(MaskSizes(1))],['m=',num2str(MaskSizes(2))],['m=',num2str(MaskSizes(3))],['m=',num2str(MaskSizes(4))],['m=',num2str(MaskSizes(5))],0);
legend(['m=',num2str(MaskSizes(1))],['m=',num2str(MaskSizes(2))],['m=',num2str(MaskSizes(3))],0);
hold off
print(1,'-dpng','-r90',['StudyResults','\',testimg,'-LT',num2str(flipT),'-m',num2str(MaskSizes(1)),'-',num2str(MaskSizes(testmnum)),'.png']);
delete(1);    
fclose(fid);

Contact us