How can I fix this when the value is constantly changing when measuring PSNR?
Show older comments
clc
k=imread('clue.jpg');
k=rgb2gray(k);
subplot(3,3,1);
imshow(k)
ks=double(k);
%Periodic noise
%diagonal noise
[x,y]=meshgrid(1:512,1:512);
p=1+sin(x+y);
tp=(ks/128+p)/4;
%Vertical noise
sig=30/255;
ks(:,:) = ks(:,:)/255;
for i=1:3:512
y=randn;
ks(:,i) = ks(:,i) + sig*y;
end
ts=(tp+ks)/2;
subplot(3,3,2);
imshow(ts)
%Frequency domain
tf=fftshift(fft2(tp));
tfs=10*log(1+abs(tf));
subplot(3,3,3);
imshow(tfs,[])
%lpf design
fr=zeros(512,512);
row=512;
col=512;
pok1=70;
pok2=70;
%Rectangle
for x=row/2-pok1:1:row/2+pok1
for y=col/2-pok2:1:col/2+pok2
fr(x,y)=1;
end
end
%Rhombus
R = [350 250 ;
250 350 ;
150 250 ;
250 250] ;
[X,Y] = meshgrid(1:512,1:512) ;
idx = inpolygon(X,Y,R(:,1),R(:,2)) ;
fr(idx) = 1 ;
U = [350 250 ;
250 150 ;
150 250 ;
250 250] ;
[X,Y] = meshgrid(1:512,1:512) ;
idx = inpolygon(X,Y,U(:,1),U(:,2)) ;
fr(idx) = 1 ;
subplot(3,3,4);
imshow(fr)
%noise reduction
J=tf.*fr;
subplot(3,3,5);
imshow(J);
J1=ifftshift(J);
j=ifft2(J1);
subplot(3,3,6);
j=abs(j);
imshow(j);
%measure psnr
peaksnr=psnr(j,ks);
fprintf('The PSNR value is %0.4f.\n',peaksnr);
double ks value keeps changing...ㅠ
How can I get a fixed PSNR value?
2 Comments
Walter Roberson
on 31 Aug 2019
We expect ks to keep changing: you are adding randn() to it.
randn() has a statistical distribution; you should not expect that two different random runs will give you exactly the same PSNR -- not unless you use rng() to set a particular random number seed.
Ju Hee Hwang
on 31 Aug 2019
Answers (0)
Categories
Find more on Descriptive Statistics 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!