📄 prova.m
字号:
% DCT-based image watermarking
% Digital watermarking has been proposed as a viable solution
% to the need of copyright protection and authentication
% of multimedia data in a networked environment, since
% it makes possible to identify the author, owner, distributor
% or authorized consumer of a document. In this paper a new
% watermarking technique to add a code to digital images is
% presented: the method operates in the frequency domain
% embedding a pseudo-random sequence of real numbers in a
% selected set of DCT coeficients. Watermark casting is performed
% by exploiting the masking characteristics of the Human
% Visual System, to ensure watermark invisibilily. The
% embedded sequence is extracted without resorting to the
% original image, so that the proposed technique represents
% a major improvement to methods relying on the comparison
% between the watermarked and original images. Experimental
% results demonstrate that the watermark is robust to
% most of the signal processing techniques and geometric distortions.
%
% For the complete source code please visit
% http://www.advancedsourcecode.com/dctwater.asp
%
% For more information please email me luigi.rosa@tiscali.it
%
% References
% A. Piva, M. Barni, F. Bartolini, and V. Cappellini,
% "DCT-based watermark recovering without restoring
% to the uncorrupted original image", in International
% Conference on Image Processing, vol. 111, pp. 520-523, 1997.
% This article is available at
% http://www.tsi.enst.fr/~maitre/tatouage/icip97/piva-97.pdf
%
%
% Luigi ROSA
% Via Centrale 35
% 67042 Civiata Di Bagno
% L'Aquila - ITALY
% mobile +39 3207214179
% email luigi.rosa@tiscali.it
% website http://www.advancedsourcecode.com
%
clc;clear;close all;
enablevisualization = 1; % this parameter enables visualization of images
img = imread('v17.jpg'); % image acquisition
img = rgb2gray(img); % image is converted from RGB to GRAYSCALE. Not necessary
% if the input image is grayscale.
img0 = img;
img = double(img); % input grayscale image
L = 25000; % the lowest L coefficients that are skipped (see the cited article)
M = 16000; % the length of the watermark (see the cited article)
x = randn(M,1); % the watermark has a normal distribution (pseudo-random sequence)
visualmasking = 1; % the visual masking option. If 1 it is enabled.
alfa = 6.2; % if visualmasking is enabled (1) alfa has to be greater (6.2 is a good value).
% Otherwise (visualmasking is not enabled 0) a good value for alfa is 0.2.
% In the first case (visual masking enabled) the effective value of alfa is alfa_new = alfa_old * factor
% (see the cited article for more details). In the second case
% (visual masking not enabled) the value of alfa has NOT to
% be changed.
R = 9; % the window of the square block size for the computation of variance
% when the visual masking is enabled. If visualmasking = 0
% this value is not used.
% the watermarked image is calculated. If visual masking (visualmasking) is enabled
% a new value for the alfa has to be considered. Otherwise the value
% of alfa is not changed.
[watermarked_image,alfa] = wm_casting(img,x,L,alfa,R,visualmasking);
% Watermark casting
% [watermarked_image,alfa] = wm_casting(img,x,L,alfa,R,visualmasking)
% img: input image
% x: watermark whisch has to be added to the image
% L: skipped DCT coefficients
% alfa: watermarking parameter
% R: block size (if viasual masking is enabled)
% visualmasking: if 1 the visual masking is enabled
% image
% watermarked_image: watermarked image
% alfa: the new value of alfa (if visual masking is not
% enable this value is not changed)
%
% watermarked_image is the watermarked image
% NOTE: the watermarked image can be saved as a grayscale image (uint8
% type). In fact it is not necessary that the watermarkled image is a
% double matrix.
watermarked_image = double(uint8(watermarked_image));
if enablevisualization
% visualization
figure('Name','Input grayscale image');
imshow(img0);
pause(0.3);
figure('Name','Watermarked image');
imshow(uint8(watermarked_image));
pause(0.3);
figure('Name','Different pixels');
imshow(watermarked_image~=img0);
pause(0.3);
end
% image degradation
% ...
% ...
%corrupted_image = watermarked_image; % if no noise is introduced
corrupted_image = double(watermarked_image)+130*rand(size(watermarked_image)); % if some noise is introduced
% now the watermarked image is corrupted by noise
% ...
% ...
if enablevisualization
% visualization
figure('Name','Corrupted image');
imshow(uint8(corrupted_image));
pause(0.3);
end
% the correct watermark (it should be revealed)
[z,Sz] = wm_detection(corrupted_image,x,L,alfa);
% Watermark detection
% [z,Sz] = wm_detection(watermarked_image,x,L,alfa)
% watermarked_image: input, watermarked (and evantually corrupted)
% image
% x: watermark
% L: number of initial skipped coefficients
% alfa: watermarking parameter
% z: computed correlation
% Sz: thereshold correlation. If z >= Sz the watermarked
% image was created using x vector
% a wrong watermark (it should not be revealed)
%[z,Sz] = wm_detection(corrupted_image,randn(size(x)),L,alfa);
% results: the corruped image is the watermarked image?
disp('Test results:');
if z >= Sz
disp('Watermarked image');
else
disp('Non-watermarked image');
end
disp('* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *');
disp('For the complete source code please visit');
disp('http://www.advancedsourcecode.com/dctwater.asp');
web http://www.advancedsourcecode.com/dctwater.asp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -