problem in executing,wiener program
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have been working on the wiener filter for images, and have a question regarding the executing when I want to execute my program,this problem appear and I do not know how to solve it.
My Program
clc;
x = imread('lena.jpg');
[m n]=size(x);
figure(1),
imshow(x);
%%adding noise to image .
afterNoise = imnoise(x,'gaussian',0,0.025);
figure,
imshow(afterNoise);
%Implementing Wiener filter
N = size(x,1);
Yf = fft2(x);
Hf = fft2(afterNoise,m,n);
Pyf = abs(Yf).^2/N^2;
gamma=1;
alpha=1;
sigma=1;
% direct implementation of the regularized inverse filter,
% when alpha = 1, it is the Wiener filter
% Gf = conj(Hf).*Pxf./(abs(Hf.^2).*Pxf+alpha*sigma^2);
% Since we don't know Pxf, the following
% handle singular case (zero case)
sHf = Hf.*(abs(Hf)>0)+1/gamma*(abs(Hf)==0);
iHf = 1./sHf;
iHf = iHf.*(abs(Hf)*gamma>1)+gamma*abs(sHf).*iHf.*(abs (sHf)*gamma<=1);
Pyf = Pyf.*(Pyf>sigma^2)+sigma^2*(Pyf<=sigma^2);
Gf = iHf.*(Pyf-sigma^2)./(Pyf-(1-alpha)*sigma^2);
% max(max(abs(Gf).^2)) % should be equal to gamma^2
% Restorated image without denoising
eXf = Gf.*Yf;
ex = real(ifft2(eXf));
figure(3),
imshow(ex,gray(256));
Please help me, not ignore my question.
Thanks in advance
Réponse acceptée
Andrew Newell
le 23 Avr 2011
Your problem occurs in this line:
y = real(ifft2(Hf.*Xf))+sigma*randn(N,N); % circular convolution
Your noise term does not have the same dimensions as your image data. Try these two commands instead:
y = real(ifft2(Hf.*Xf)); % circular convolution
y = y + sigma*randn(size(y)); % add noise
I don't know if it will do what you are trying to do, but at least it doesn't produce an error.
A note on debugging scripts: You can locate the error more easily if you sprinkle the code with the occasional cell marker, e.g.,
N = 256;
x = imread('lena.jpg');
figure(1)
imshow(x)
This allows you to run small blocks of code at a time, and you can narrow down the source of the error to a single block. See Evaluating Subsections of Files Using Code Cells.
2 commentaires
Andrew Newell
le 27 Avr 2011
One of your lines is returning an error:
Gf = iHf.*(Pyf-sigma^2)./(Pyf-(1-alpha)*sigma^2);
??? Array dimensions must match for binary array op.
It's because iHf and Pyf do not have the same dimensions.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Filtering and Enhancement dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!