How can I fix this when the value is constantly changing when measuring PSNR?

조회 수: 2 (최근 30일)
Ju Hee Hwang
Ju Hee Hwang 2019년 8월 31일
댓글: Ju Hee Hwang 2019년 8월 31일
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
Walter Roberson
Walter Roberson 2019년 8월 31일
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
Ju Hee Hwang 2019년 8월 31일
rng('default');
y=randn();
This change made the value fixed.
It was very helpful:)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by