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.

RandNoise(ImName,Dimention,AbsError,RunTimes,plot_rownum,plot_colnum,IncVal)
function RandNoise(ImName,Dimention,AbsError,RunTimes,plot_rownum,plot_colnum,IncVal)
%dbstop 54

if exist([ImName,'Dimention',num2str(Dimention),'RandNoiseError',num2str(AbsError)])==0
   mkdir([ImName,'Dimention',num2str(Dimention),'RandNoiseError',num2str(AbsError)]);
end

img0=double(imread([ImName,'.png']));
imwrite(mat2gray(img0),[[ImName,'Dimention',num2str(Dimention),'RandNoiseError',num2str(AbsError)],'\',ImName,'.png'],'bitdepth',1);
img=img0;
DistTable=CalDisTable(ImName,Dimention);
[rows,cols]=find(DistTable~=1);
[i,j]=size(rows);
TotalDist=0;
AveDist=0;
RowLength=0;
ColLength=0;
graph_num=0;
splot_num=1;
SaveDist=1;


for circle=1:800
    for m=1:AbsError
        ChoosePoint=randperm(i);
        InterIndex=ChoosePoint(1);
        RowIndex=rows(InterIndex);
        ColIndex=cols(InterIndex);
    
        select=binornd(1,0.25)+1;
        switch select
        case 1,
            RowLength=double(uint16(rand(1,1)*3))-1;
            ColLength=double(uint16(rand(1,1)*3))-1;
            TotalDist=TotalDist+DistTable((RowIndex+RowLength),(ColIndex+ColLength));
            RowLength=0;
            ColLength=0;
        case 2,
            while(~((abs(RowLength)==2)||(abs(ColLength==2))))
                RowLength=double(uint16(rand(1,1)*5))-2;
                ColLength=double(uint16(rand(1,1)*5))-2;
            end
            TotalDist=TotalDist+DistTable((RowIndex+RowLength),(ColIndex+ColLength));
            RowLength=0;
            ColLength=0;
        end
    end
    AveDist=TotalDist/AbsError;
    if AveDist<=SaveDist
        SaveDist=AveDist;
    end
    TotalDist=0;
    AveDist=0;
end


for time=1:RunTimes
while (abs(AveDist-SaveDist)>0.01)
    img=img0;
    for m=1:AbsError
        ChoosePoint=randperm(i);
        InterIndex=ChoosePoint(1);
        RowIndex=rows(InterIndex);
        ColIndex=cols(InterIndex);
    
        select=binornd(1,0.25)+1;
        switch select
        case 1,
            RowLength=double(uint16(rand(1,1)*3))-1;
            ColLength=double(uint16(rand(1,1)*3))-1;
            TotalDist=TotalDist+DistTable((RowIndex+RowLength),(ColIndex+ColLength));
            img((RowIndex+RowLength),(ColIndex+ColLength))=~img((RowIndex+RowLength),(ColIndex+ColLength));
        case 2,
            while(~((abs(RowLength)==2)||(abs(ColLength==2))))
                RowLength=double(uint16(rand(1,1)*5))-2;
                ColLength=double(uint16(rand(1,1)*5))-2;
            end
            TotalDist=TotalDist+DistTable((RowIndex+RowLength),(ColIndex+ColLength));
            img((RowIndex+RowLength),(ColIndex+ColLength))=~img((RowIndex+RowLength),(ColIndex+ColLength));
        end
    end
    AveDist=TotalDist/AbsError;
    TotalDist=0;
end
    SaveDist=SaveDist+IncVal;
    imwrite(mat2gray(img),[[ImName,'Dimention',num2str(Dimention),'RandNoiseError',num2str(AbsError)],'\',ImName,'AbsError',num2str(AbsError),'AveDist',num2str(AveDist),'.png'],'bitdepth',1);
    if splot_num==1
        subplot(plot_rownum,plot_colnum,splot_num),imshow(img0),title([ImName,'Dimen',num2str(Dimention),'AbsE',num2str(AbsError)])  ;
        splot_num=splot_num+1;
    end
    if splot_num>1   
        title_name=sprintf('AbsE%dAveD%.2f',AbsError,AveDist);
        subplot(plot_rownum,plot_colnum,splot_num),imshow(img),title(title_name)
        splot_num=splot_num+1;
    end
    if splot_num==plot_rownum*plot_colnum+1
        print(1,'-dpng','-r90',[[ImName,'Dimention',num2str(Dimention),'RandNoiseError',num2str(AbsError)],'\',ImName,'RandNoise',num2str(graph_num),'.png']);
        graph_num=graph_num+1;
        delete(1);
        splot_num=1;
    end
    AveDist=0;
    TotalDist=0;
    img=img0;
    if SaveDist>=1
        break
    end
end


if splot_num<=plot_rownum*plot_colnum
   for control=splot_num:(plot_rownum*plot_colnum)
   title_name=sprintf([ImName,'Dimen',num2str(Dimention),'AbsE',num2str(AbsError)]);
   subplot(plot_rownum,plot_colnum,control),imshow(img0),title(title_name)
      if control==plot_rownum*plot_colnum
         print(1,'-dpng','-r90',[[ImName,'Dimention',num2str(Dimention),'RandNoiseError',num2str(AbsError)],'\',ImName,'RandNoise',num2str(graph_num),'.png']);
         graph_num=graph_num+1;
         delete(1);
      end
   end
end



        
            
  
        
    
    
    
    

Contact us