PSNR value is very high around 300. Am I doing it correct?
5 次查看(过去 30 天)
显示 更早的评论
I have following code which gives me PSNR 300 which seems unrealisic. If I use DWT first level, it shows correct PSNR around 40-50dB, But 2-level DWT gives PSNR 300. Is the code incorrect.
Thank you.
------------------------------------------------------------------------------------
clear all;
close all;
clc;
format long
addpath(genpath(cd))
%% AES ENCRYPTION
ssi;
plaintext=['S' 'i' 'n' 'h' 'g' 'a' 'd' ' ' 'C' 'o' 'l' 'l' 'e' 'g' 'e' ' '];
fprintf('PLAIN TEXT :%s\n', plaintext);
plain=reshape(plaintext,4,4);
plain = abs (plain);
key = ['1' '2' '3' '4' '5' '6' '7' '8' '9' '1' '2' '3' '4' '5' '6' '7'];
key=abs(key);
w = key_expansion (key, s_box, rcon);
ciphertext = cipher (plain, w, s_box, poly_mat,ind_matleft);
ciphertext = reshape(ciphertext,1,16);
fprintf('CIPHER TEXT :%s\n',ciphertext);
pause(.2)
save ciphertext ciphertext
%% DWT DECOMPOSITION
I=imread('chest_xray.jpg');
% I=im2bw(I);
figure,imshow(I);title('COVER IMAGE');pause(.5)
% RESIZE
I=imresize(I,[512,512]);
[m,n,z]=size(I);
% m:Rows, n:Coloumns, Z:Channel
if z==3%i.e.R,G,B [it is color image]
I=rgb2gray(I);
figure,imshow(I);title('GRAY IMAGE');pause(.5)
end
% DWT DECOMPOSITION
Wname='db01';% Wavlete family --Daubechis Wavlet
% Decompose Image
[CA,CH,CV,CD]=dwt2(I,Wname);
%%https://in.mathworks.com/matlabcentral/answers/384533-how-to-calculate-discrete-wavelet-transform-on-an-image-with-levels-2-4-and-6-using-dwt2-function-in
[cDA,cDH,cDV,cDD] = dwt2(CD,Wname);
CD=cDD;
load ciphertext
CD=im2bw(CD);
CD=mat2gray(CD);
CD(1:16,1)=ciphertext;
CD=repmat(CD,2,2);
% CA:Approximate Coeff;
% DETAIL COEFF
% CH:Horizontal coeff
% CV:Vertical Coeff
% CD Diagonal Coeff
figure,
subplot(2,2,1);imagesc((CA));title('APPROX COEFF')
subplot(2,2,2);imagesc((CH));title('DETAIL COEFF:HORIZONTAL')
subplot(2,2,3);imagesc((CV));title('DETAIL COEFF:VERTICAL')
subplot(2,2,4);imagesc((CD));title('DETAIL COEFF:DIAGONAL')
%% DWT RECONSTRUCTION
% RECONSTRUCT
cDD=imresize(cDD,[128, 128]);
CD=idwt2(cDA, cDH, cDV, cDD ,Wname);
I1=idwt2(CA, CH, CV, CD, Wname);
figure,
imshow(I1,[]),title('RECONSTRUCTED IMAGE')
%%Performance
I = double(I);
%%https://www.pantechsolutions.net/blog/matlab-code-for-psnr-and-mse/
n=size(I);
M=n(1);
N=n(2);
MSE = sum(sum((I-I1).^2))/(M*N);
%PSNR = 10*log10(256*256/MSE); 1.879471168418133e-27
PSNR = 10*log10(256*256/1.879471168418133e-27);
fprintf('\nMSE: %7.2f\n', MSE);
fprintf('PSNR: %10.10f dB\n', PSNR);
ssimval = ssim(I1,I);
fprintf('Structural Similarity: %5.5f\n\n', ssimval);
2 个评论
KALYAN ACHARJYA
2019-7-23
Please share the MSE value? also mention the image bit type (8 bit image or 16 bit)?
Punitha Viswanathan
2022-4-5
did you get the answer for why the PSNR value comes above 300. please answer. Thanks in advance
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!