Can PSNR be infinity

16 views (last 30 days)
Manpreet
Manpreet on 8 Jun 2015
Commented: Walter Roberson on 22 Oct 2016
I am doing thesis on Image watermarking using DWT(Discrete Wavelet Transforms) and encryption using random permutations. After applying various attacks such as rotation, scaling, croping,contrast, I am getting PSNR between Original watermark and Decrypted watermark equal to Infinity.
Can this Possible????????????????
I am attaching my code and picture along with this..................
[i11,i12]=uigetfile('*.jpg;*.png;*.tif;*bmp');
i12=strcat(i12,i11); %String Concatenation
i1=imread(i12); %Image is read and stored in the variable i1
i1= imresize(i1,[256 256]); %resizing the image with new dimensions as 512*512
[l,m,n]=size(i1); %displaying the dimensions of Image
P1=im2double(i1); %Convert the integer image into double image as it gives more Precised value
%Did 3 level DWT
[F1,F2]= wfilters('haar', 'd');
[LL,LH,HL,HH] = dwt2(P1,'haar','d'); %One Level DWT
[LL1,LH1,HL1,HH1] = dwt2(LL,'haar','d'); %Two Level DWT
[LL2,LH2,HL2,HH2] = dwt2(LL1,'haar','d') %Three Level DWT
[a,b]= uigetfile('*.jpg;*.png;*.tif;*bmp'); %Fetching the Image to be watermarkedXXXXXXXXXX%
b= strcat(b,a); %String Concatenation
c=imread(b); %Image is read and stored in the variable c
c= imresize(c,[64 64]); %resizing the image with new dimensions as 64*64
[p,q,r]=size(c); %displaying the dimensions of Image
%%%%%%%%%Cipher watermark%%%%%%%%%%%%%%%%%%%%%
scrambleOrder = randperm(p*q);
redChannel = c(:, :, 1);
greenChannel = c(:, :, 2);
blueChannel = c(:, :, 3);
redChannel = redChannel(scrambleOrder);
greenChannel = greenChannel(scrambleOrder);
blueChannel = blueChannel(scrambleOrder);
redChannel = reshape(redChannel, [p,q]);
greenChannel = reshape(greenChannel, [p,q]);
blueChannel = reshape(blueChannel, [p,q]);
s = cat(3, redChannel, greenChannel, blueChannel);
%converting the encrypted image into one level dwt
f= im2double(s);
[F1,F2]= wfilters('haar', 'd');
[LL11,LH11,HL11,HH11] = dwt2(f,'haar','d'); %one level dwt of the encrypted image
%LL11 = imresize(LL11,[64 64]);
k = LL2 + 0.001*LL11.*LL2;
Watermarkedimage_level1= idwt2(k,LH2,HL2,HH2,'haar'); %reconstruction of the watermark level3
Watermarkedimage_level2=idwt2(Watermarkedimage_level1,LH1,HL1,HH1,'haar'); %reconstruction of the watermark level2
Watermarkedimage_final=idwt2(Watermarkedimage_level2,LH,HL,HH,'haar'); %reconstruction of the watermark level1
%%%%%%%%%%%%%%%rotation attack%%%%%%%%%%%%%%%%%%%%%%%
%data = clipboard('pastespecial')
J = imresize(Watermarkedimage_final,[220 140]);
[N1 L1 B1] = size(J);
%axis tight;
%%%%%%%PSNR and MSE between Host Image and Watermarked
%%%%%%%Image%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%Recovery of watermark fromm attacked image%%%%%%%%%%%%%%%%%%%%%%%%%%
[a b c1 d]=dwt2(J,'haar','d');
[aa bb cc dd]=dwt2(a,'haar','d');
[aaa bbb ccc ddd]=dwt2(aa,'haar','d');
aaa = imresize(aaa,[N1/3 L1/3]);
LL2 = imresize(LL2,[N1/3 L1/3]);
Recovered_watermark = [(aaa ./LL2)-1]./0.001;
%imshow(Recovered_watermark);
Recovered_watermark1 = imresize(Recovered_watermark,[32 32]);
Wavelet_reconstruction=idwt2(Recovered_watermark1,LH11,HL11,HH11,'haar');
[u v z] = size(Wavelet_reconstruction);
%scrambleOrder1 = randperm(u*v);
%%%%%%%%%%Decryption of Watermark%%%%%%%%%%%
recoverOrder = zeros([u*v], 2);
recoverOrder(:, 1) = 1 : (u*v);
recoverOrder(:, 2) = scrambleOrder;
newOrder1 = sortrows(recoverOrder, 2);
newOrder = newOrder1(:,1);
redChannel = redChannel(newOrder);
greenChannel = greenChannel(newOrder);
blueChannel = blueChannel(newOrder);
redChannel = reshape(redChannel, [u, v]);
greenChannel = reshape(greenChannel, [u, v]);
blueChannel = reshape(blueChannel, [u, v]);
D = cat(3, redChannel, greenChannel, blueChannel);
s= im2double(s);
squaredErrorImage = (c-D).^ 2;
MSE=sum(sum(squaredErrorImage)) / (p* q)
MaxI=1; %maX INDICATES THE Maximum Value of the Pixles
PSNR=10*log10((MaxI^2)/MSE)
channelToCorrelate = 1; % Use the red channel.
correlationOutput = normxcorr2(D(:,:,1), c(:,:, channelToCorrelate));
[rows, columns, numberOfColorBands] = size(correlationOutput);
[maxCorrValue, maxIndex] = max(abs(correlationOutput(:)))
channelToCorrelate = 2; % Use the green channel.
correlationOutput = normxcorr2(D(:,:,1), c(:,:, channelToCorrelate));
[rows, columns, numberOfColorBands] = size(correlationOutput);
[maxCorrValue, maxIndex] = max(abs(correlationOutput(:)))
channelToCorrelate = 3; % Use the green channel.
correlationOutput = normxcorr2(D(:,:,1), c(:,:, channelToCorrelate));
[rows, columns, numberOfColorBands] = size(correlationOutput);
[maxCorrValue, maxIndex] = max(abs(correlationOutput(:)))
subplot(3, 3, 1);imshow(i1);title('Message Image');
subplot(3, 3, 2);imshow(c);title('Watermark image');
subplot(3, 3, 3);imshow(s);title('Encrypted Watermark');
subplot(3,3,4);imshow(Watermarkedimage_final);title('Watermarked Final');
subplot(3, 3, 5);imshow(J);title('Scaled Watermarked Image');
subplot(3, 3, 6);imshow(D);title('Decrypted Watermark');
figure;surf(correlationOutput);title('correlationOutput');
%%%%%%%PSNR and MSE between Host Image and Watermarked
%%%%%%%Image%%%%%%%%%%%%%%%%%%%%
%squaredErrorImage = (P1 - J) .^ 2;
%%MSE=sum(sum(squaredErrorImage)) / (l * m)
%MaxI=1; %maX INDICATES THE Maximum Value of the Pixles
%PSNR=10*log10((MaxI^2)/MSE)
%%%%%%%%%%%%%PSNR and MSE between Encrypted and Extracted
%%%%%%%%%%%%%Image%%%%%%%%%%%%%%%%%%%%
%i3= im2double(i3);
%squaredErrorImage = (s - Wavelet_reconstruction).^ 2;
%MSE=sum(sum(squaredErrorImage)) / (p* q)
%MaxI=1; %maX INDICATES THE Maximum Value of the Pixles
%PSNR=10*log10((MaxI^2)/MSE)
%%%%%%%PSNR and MSE between watermark and Decrypted
%%%%%%%Image%%%%%%%%%%%%%%%%%%%%%%%%

Answers (1)

Walter Roberson
Walter Roberson on 8 Jun 2015
Yes, PSNR is infinity if the two images being compared are exactly the same.
  2 Comments
amira fauzey
amira fauzey on 22 Oct 2016
can i ask? My original image PSNR value is infinity is it correct?and my MSE value of original image is 0.original image means before i add noise to the image
Walter Roberson
Walter Roberson on 22 Oct 2016
Correct, if you compare two identical images, the PSNR is infinity and the MSE is 0.

Sign in to comment.

Categories

Find more on Discrete Multiresolution Analysis in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!