这个Matlab程序的最主要功能在water.m文件中,当你调用这个函数之后,
系统会提示你给哪个图像文件加水印。blockdwt2.m文件,用于在小波频域添加水印logo图片。dmg.m文件产生水印logo图片。
watdet3.m文件中的函数实现的功能是检查是否有水印的logo存在。
包含的文件有:dmg.m, watdet3.m, watrm.m, blockdwt2.m,
主函数是water.m,它会提示你输入图像。
blockdwt2.m添加一个水印图片到小波域。
dmg.m产生水印的LOGO。
watdet3.m检查LOGO水印。
程序如下:
blockdwt2.m
function [D]=blockdwt2(A,W);
[row,col]=size(A);
Tr=250;
k=0.02;
[ca,ch,cv,cd] = dwt2(A,'db1');
c1 = [ch cv cd];
[h, w] = size(ca');
[m, n] = size(c1');
W=dmg(W,A);
[caa chh cvv cdd]=dwt2(W,'db1');
W=caa;
size(W);
% Adding watermark image.
for i=1:h
for j=1:w
if ca(i,j)>Tr
Ca(i,j)=ca(i,j)+k*W(i,j); % <--------k*abs(double(c1(i,j)))*W(i,j); de olabilir
else
Ca(i,j)=ca(i,j);
end
end
end
% CH1=C1(1:h,1:w);
% CV1=C1(1:h,w+1:2*w);
% CD1=C1(1:h,2*w+1:3*w);
D= double( idwt2(Ca,ch, cv, cd,'db1') );
dmg.m
% Damga uretme
%
% imgew: Damga imgesi
% imge1: Orjinal imge
%
function W=dmg(imgew,imge1);
[w h]=size(imgew');
[w1 h1]=size(imge1');
a=1;
b=1;
W=zeros(size(imge1'));
for i=1:w:w1
for j=1:h:h1
W(i:a*w,j:b*h)=imgew';
b=b+1;
end
a=a+1;
b=1;
end
W=W';
watdet3.m
function W=watdet3(watermarkim,originalim);
a=marked-image1;
[ca ch cv cd]=dwt2(a,'db1');
imshow(ca);
watrm.m
clear all; close all; clc;
[filename1,pathname]=uigetfile('*.*','select the image');
image1=imread(num2str(filename1));
figure(1);
imshow(image1); title('original image'); % orginal image for watermarking
image1=double(image1);
[row,col]=size(image1);
imagew=imread('dmg2.tif');
[marked]=blockdwt2(image1,imagew); % generates the watermarked image
markedmax = max(marked(:));
markscale = marked/markedmax*255;
figure(2);
colormap(gray(256));
image(marked); % shows the watermarked image
title('Watermarked image');
imwrite(marked,gray(256),'marked_image.bmp'); % saves the watermarked image as a bmp file
figure(3);
watermark=image1-marked; % image adaptive watermark
watermark=watermark*255/max(watermark(:));
for i = 1:row % thresholding
for j = 1:col
if watermark(i,j) > 70
watermark(i,j) = 255;
end
if watermark(i,j) < 70
watermark (i,j) = 0;
end
end
end
colormap(gray(256));
image(watermark); % shows the image adaptive watermark
title('watermark');
imwrite(marked,gray(256),'watermark.bmp'); % saves the image adaptive watermark as a bmp file