⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waterdem.m

📁 这是一个matlab程序包
💻 M
字号:
function waterdem(action,varargin);
% This is a water Marking Demonstration,includes a host image, watermark image
% Resultent images are Watermarked image and at decoder, Reconstructed water mark.
% Coded by :- Ravi Lakkundi, M.Tech, SDMCET Dharwad
% Submitted as a Mini Project for the course of Digital Image Processing
% This code is to be viewed only with permission from author
% Started 15/06/2003 at 0600 Hrs, Completed 15/06/2003 at 2000 Hrs

if nargin<1,
   action='InitializewatDEMO';
end;

feval(action,varargin{:});
return;

function InitializewatDEMO()

% If program is already running bring it to front
h = findobj(allchild(0), 'Name', 'Water Marking Demonstration : Ravi Lakkundi , M.Tech');
if ~isempty(h)
   figure(h(1))
   return
end

waterdemofig=figure('Name','Water Marking Demonstration : Ravi Lakkundi , M.Tech','resize','on','NumberTitle','off'); % This is parent figure
set(gcf,'units','centimeters');
% Control panel Frame is constructed
%bagr=get(waterdemofig,'BackgroundColor');

hframe=uicontrol('parent',waterdemofig,'style','frame','position',...
                   [470 0 90 500],'BackgroundColor',[0.45 0.45 0.45]);
               
hwater=uicontrol('parent',waterdemofig,'style','pushbutton','string','WaterMark',...
                  'position',[470 357 90 27],'callback','waterdem(''showwatmar'')');
              
hhost=uicontrol('parent',waterdemofig,'style','pushbutton','string','Host',...
                  'position',[470 300 90 27],'callback','waterdem(''showhost'')'); 
              
hctr=uicontrol('parent',waterdemofig,'style','pushbutton','string','CREATE',...
                  'position',[470 210 90 27],'enable','off','callback','waterdem(''calculate'')');
              
htxd=uicontrol('parent',waterdemofig,'style','pushbutton','string','Watermarked',...
                  'position',[470 120 90 27],'enable','off','callback','waterdem(''findtxr'')');
              
hrxr=uicontrol('parent',waterdemofig,'style','pushbutton','string','Recstrted WM',...
                  'position',[470 66 90 27],'enable','off','callback','waterdem(''findrxr'')');
 
              
%hwait=uicontrol('parent',waterdemofig,'style','text','string',...
 %                 ' Please Wait ........... This might take few minutes',...
  %               'position',[0 242 469 20],'fontweight','bold','Visible','off','fontsize',9);%'BackgroundColor',[0 0 1]);
              
%hamt=uicontrol('parent',waterdemofig,'style','slider','string','Transparency',...
%                  'position',[500 200 20 87]);  

uicontrol('parent',waterdemofig,'style','text','string',...
                  ' By:  Ravi Lakkundi , M.Tech',...
                 'position',[0 402 469 20],'fontweight','bold','fontsize',9);%,'BackgroundColor',[1 1 1.0]);

hclose=uicontrol('parent',waterdemofig,'style','pushbutton','string','CLOSE',...
                  'position',[470 10 90 27],'callback','close(gcf)'); 

%=============================================================              
% Set up the image axes
%=============================================================
hwtrue = axes('Parent', waterdemofig, ...
   'units', 'pixels', ...
   'BusyAction','Queue','Interruptible','off',...
   'ydir', 'reverse', ...
   'XLim', [0.5 128.5], ...
   'YLim', [0.5 128.5],...
   'CLim', [0 1], ...
   'XTick',[],'YTick',[], ...
   'Position', [60 280 100 100]);title('Watermark');
blank = repmat(uint8(0),0,0);

hwtrueimage = image('Parent', hwtrue,...
    'CData', blank);%, ...
   %'BusyAction','Queue','Interruptible','off',...
%   'CDataMapping', 'scaled', ...
%   'Xdata', [0 128],...
%   'Ydata', [0 128],...
%   'EraseMode', 'none');

% ==========================================================
hhtrue = axes('Parent', waterdemofig, ...
   'units', 'pixels', ...
   'BusyAction','Queue','Interruptible','off',...
   'ydir', 'reverse', ...
   'XLim', [.5 128.5], ...
   'YLim', [.5 128.5],...
   'CLim', [0 1], ...
   'XTick',[],'YTick',[], ...
   'Position', [10 10 200 200]);title('Original Image');
%blank = repmat(uint8(0),128,128);

hhtrueimage = image('Parent', hhtrue,...
   'CData', blank, ...
   'BusyAction','Queue','Interruptible','off',...
   'CDataMapping', 'scaled', ...
   'Xdata', [1 128],...
   'Ydata', [1 128],...
   'EraseMode', 'none');

%==============================================================
hhwmed = axes('Parent', waterdemofig, ...
   'units', 'pixels', ...
   'BusyAction','Queue','Interruptible','off',...
   'ydir', 'reverse', ...
   'XLim', [.5 128.5], ...
   'YLim', [.5 128.5],...
   'CLim', [0 1], ...
   'XTick',[],'YTick',[], ...
   'Position', [300 280 100 100]);title('Reconstructed WM');
%blank = repmat(uint8(0),128,128);

hhwmedtrue = image('Parent', hhwmed,...
   'CData', blank, ...
   'BusyAction','Queue','Interruptible','off',...
   'CDataMapping', 'scaled', ...
   'Xdata', [1 128],...
   'Ydata', [1 128],...
   'EraseMode', 'none');

%================================================================
hhwm = axes('Parent', waterdemofig, ...
   'units', 'pixels', ...
   'BusyAction','Queue','Interruptible','off',...
   'ydir', 'reverse', ...
   'XLim', [.5 128.5], ...
   'YLim', [.5 128.5],...
   'CLim', [0 1], ...
   'XTick',[],'YTick',[], ...
   'Position', [250 10 200 200]);title('Watermarked Image');
%blank = repmat(uint8(0),128,128);

hhtruewm = image('Parent', hhwm,...
   'CData', blank, ...
   'BusyAction','Queue','Interruptible','off',...
   'CDataMapping', 'scaled', ...
   'Xdata', [1 128],...
   'Ydata', [1 128],...
   'EraseMode', 'none');

%================================================================

% Put handles to graphics objects and controls in the figure's userdata
handles.wtrue=hwtrue;
handles.wtrueimage=hwtrueimage;
handles.htrue=hhtrue;
handles.htrueimage=hhtrueimage;
handles.hwmed=hhwmed;
handles.hwmedtrue=hhwmedtrue;
handles.hwm=hhwm;
handles.htruewm=hhtruewm;
handles.txd=htxd;
handles.rxr=hrxr;
handles.water1=hwater;
handles.host1=hhost;
handles.hhctr=hctr;
%handles.waith1=hwait;

set(waterdemofig, 'UserData',handles);
%set(waterdemofig, 'HandleVisibility','Callback')

return
%=================================================================

function showwatmar(demfig)

if nargin<1
   demfig = gcbf;
end
%--------------------------
handles = get(demfig,'UserData');
hwtrueimage=handles.wtrueimage;
htrue=handles.wtrue;
axes(htrue)
set(gcf,'CurrentAxes',htrue)
%--------------------------

[pth,fname] = dlgopen('open','*.bmp');
filename=[pth,fname];
filename1=filename;
handles.f1=filename1;
i=imread(filename);
imshow(i(1:128,1:128)),title('Watermark');
set(demfig,'UserData',handles);
%set(hwtrueimage,'CData',i);

%==================================================================

function showhost(demfig)

if nargin<1
   demfig = gcbf;
end

[pth,fname] = dlgopen('open','*.bmp');
filename=[pth,fname];
filename2=filename;
%------------------------------
handles = get(demfig,'UserData');
hhtrueimage=handles.htrueimage;
hhtrue=handles.htrue;
handles.f2=filename2;
axes(hhtrue);
set(gcf,'CurrentAxes',hhtrue);
%------------------------------
i=imread(filename);
imshow(i(1:256,1:256)),title('Original Image');

hwater=handles.water1;
hhost=handles.host1;
hctr=handles.hhctr;
set([hwater hhost], 'Enable', 'off');
set(hctr,'Enable','on');
set(demfig,'UserData',handles);

%===================================================================

function calculate(demfig)

if nargin<1
   demfig = gcbf;
end

set(demfig,'Pointer','watch'); drawnow; % Pointer busy

handles = get(demfig,'UserData');
hctr=handles.hhctr; % turn off CREATE
%hwait=handles.waith1;
%setstatus('string','Please wait');
set(hctr, 'Enable', 'off'); % turned off after set
%set(demfig,'UserData',handles); % turned off now

%handles = get(demfig,'UserData'); % again open handles
filename1=handles.f1;
filename2=handles.f2;

set(demfig,'UserData',handles); % turned off now
wmark = imread(filename1); %loading the watermark image
wmark = double(wmark(1:128,1:128));
%The following section embeds the watermark into the host image.

host = imread(filename2); %loading the host image
host = host(1:256,1:256);
host = im2double(host);
hosto = im2double(host);
cmin = 1;%minimum block change; value picked arbitrarily: we can tune here
alpha = 0.1;  %alpha, from the paper; value arbitrary:  we can tune this, too
row=0;
for ii=1:128
    col=0;
    for jj=1:128
        selblk=[host(ii+row,jj+col:jj+1+col) host(ii+1+row,jj+col:jj+1+col)];
        k=wmark(ii,jj);
        selmeanblk=mean(selblk);
        selmaxblk=max(selblk);
        selminblk=min(selblk);
        h=1;h1=1;
        clear zl zh;
        zl = find(selblk <= selmeanblk);
        zh = find(selblk > selmeanblk);
        zlmean = sum(selblk(zl))/length(selblk(zl));
        if isempty(zh),zhmean=zlmean;
        else zhmean = sum(selblk(zh))/length(selblk(zh));
        end
        for jk=1:4
            if k==1 
                if selblk(jk) > zhmean, selblk(jk)=selmaxblk;
                elseif (selblk(jk) >= zlmean) & (selblk(jk) < selmeanblk), selblk(jk)=selmeanblk;
                else selblk(jk) = selblk(jk)+alpha;
                end;
            end
            if k==0
                if selblk(jk) < zlmean, selblk(jk)=selminblk;
                elseif (selblk(jk) >= selmeanblk) & (selblk(jk) < zhmean), selblk(jk)=selmeanblk;
                else selblk(jk) = selblk(jk)-alpha;
                end;
            end
        end
        host(ii+row,jj+col)=selblk(1);host(ii+row,jj+1+col)=selblk(2);host(ii+1+row,jj+col)=selblk(3);host(ii+1+row,jj+1+col)=selblk(4);
        col=col+1;
        clear selblk
    end
    row=row+1;
end
hosta=host;

% Decoding program starts from here

row=0;
for ii=1:128
    col=0;
    for jj=1:128
        selblk=[host(ii+row,jj+col:jj+1+col) host(ii+1+row,jj+col:jj+1+col)];
        selblko=[hosto(ii+row,jj+col:jj+1+col) hosto(ii+1+row,jj+col:jj+1+col)];
        if(sum(selblk)>sum(selblko)) waterb(ii,jj)=1; end
        if(sum(selblk)<=sum(selblko)) waterb(ii,jj)=0; end
        col=col+1;
    end
    row=row+1;
end

handles = get(demfig,'UserData');
handles.watermd=hosta;
handles.rec=waterb;
htxd=handles.txd; % turn on buttons
hrxr=handles.rxr; % turn on button
%hwait=handles.waith1;
%setstatus('string', ''); % turned off after set
set([htxd hrxr], 'Enable', 'on');
set(demfig,'UserData',handles);

set(demfig,'Pointer','arrow'); drawnow % Pointer free

%==================================================================================

function  findtxr(demfig)

if nargin<1
   demfig = gcbf;
end

%------------------------------
handles = get(demfig,'UserData');
hhwm=handles.hwm;
axes(hhwm);
hosta=handles.watermd;
set(gcf,'CurrentAxes',hhwm);
%------------------------------
imshow(hosta),title('Watermarked Image');

%===================================================================================

function  findrxr(demfig)

if nargin<1
   demfig = gcbf;
end

%------------------------------
handles = get(demfig,'UserData');
hhwmed=handles.hwmed;
axes(hhwmed);
waterb=handles.rec;
set(gcf,'CurrentAxes',hhwmed);
%------------------------------
imshow(waterb),title('Reconstructed WM');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -