watermarking using dwt2 and psnr
Show older comments
how to calculate the psnr between the original image and the watermarked image? here is my code:
clc;clear all;close all; [filename1,pathname]=uigetfile('*.*','select the image'); %ouvrir une boîte de dialogue standard pour l'utilisateur image1=imread(num2str(filename1));
%img = imread('img1.bmp'); %lecture de l'image img = double(image1);%donne une double précision c = 0.00001; %Initialiser le poids du tatouage
figure,imshow(uint8(img)),title('Original Image'); [p q] = size(img);%retourner la taille de l'image
%Générer la clé diag=imread('oss.bmp'); diag=double(diag); %thresholdValue =70; %binaryImage = diag < thresholdValue; % Display the image. %figure,imshow(binaryImage, []); %caption = sprintf('Hidden Image Thresholded at %d', thresholdValue); %title(caption, 'FontSize', fontSize); figure,imshow(uint8(diag)),title('watermark'); imwrite(diag,'watermark.bmp','bmp'); N=input('entrer le niveau de décomposition: '); [Lo_D,Hi_D,~,Hi_R] = wfilters('bior3.5')%obtenir le filtre associé au ondelettes 5/3 [C,S] = wavedec2(img,N,'bior3.5') %calculer la transformée en ondelette discréte 2-D
[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('bior3.5') [C2, S2]= wavedec2(diag, N, 'bior3.5') [Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar'); [ca,ch,cv,cd] = dwt2(img,Lo_D,Hi_D); %Exécuter le tatouage %y = [C;S] %w=[C2;S2] %Z = y + c*abs(y)*w %p=p/2^N;q=q/2^N y = [ca ch;cv cd]; Y = y + c*abs(y).*diag; p=p/2;q=q/2;
for i=1:p for j=1:q %nca(i,j) = Z(i,j); %ncv(i,j) = Z(i+p,j); %nch(i,j) = Z(i,j+q); %ncd(i,j) = Z(i+p,j+q); nca(i,j) = Y(i,j); ncv(i,j) = Y(i+p,j); nch(i,j) = Y(i,j+q); ncd(i,j) = Y (i+p,j+q); end end
%Afficher l'image tatouéeR wimg = idwt2(nca,nch,ncv,ncd,Lo_D,Hi_D,Lo_R,Hi_R); figure,imshow(uint8(wimg)),title('Watermarked Image'); imwrite(uint8(wimg),'watermarked.bmp','bmp'); %% PSNR (Peak Signal to noise ratio)
if (size(img) ~= size(wimg)) error('The size of the 2 matrix are unequal')
psnr_Value = NaN;
return;
elseif (img == wimg)
disp('Images are identical: PSNR has infinite value')
psnr_Value = Inf;
return;
else
maxValue = double(max(img(:)));
% Calculate MSE, mean square error. mseImage = (double(img) - double(y)) .^ 2; [rows columns] = size(wimg);
mse = sum(mseImage(:)) / (rows * columns);
% Calculate PSNR (Peak Signal to noise ratio) psnr_Value = 10 * log10( 256^2 / mse);
end
%% correlation cor=corr2(img,wimg)
Answers (0)
Categories
Find more on Watermarking in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!