Gaussian Low Pass Filter
Afficher commentaires plus anciens
Hello Dear Experts,
I need to build a function performing the low pass filter: Given a gray scale image (type double) I should perform the Gaussian low pass filter. The filter size is given by a ratio parameter r. The values of the r parameter are between 0 and 1 - 1 means we keep all the frequencies and 0 means no frequency is passed. The DC should always stay.
Here is what I did:
function [nImg,mask] = lowPassFilter(img,r)
F = fftshift(fft2(img));
mask = fspecial('gaussian',[3 3], r);
M = fft2(mask, size(F,1), size(F,2));
Filtered = M.*F;
nImg = real(ifft2(ifftshift(Filtered)));
end
P.S Please tell me what I did wrong, I have been advised by Anton Semechko: "The are two fundamental ways you can perform linear filtering of an image. One approach is to use convolution in the spatial domain. The second approach is to find the product of the filter's and image's Fourier transforms in the frequency domain and then take the inverse. Now what you are attempting to do is more like the send approach. But I see two major problems with your code. First, you don't center the image on the DC component (see fftshift) after taking the FT. Secondly, you don't zero pad the filter to match the dimensions of the image."
Please tell me if I did it right or where are my mistakes. Maybe you have an example image to test on and compare to real right result that should be.
Will appreciate if your answer will be informative and straight to the point.
Réponse acceptée
Plus de réponses (1)
Habtamu Fanta
le 1 Nov 2021
0 votes
function [nImg,mask] = lowPassFilter(img,r)
F = fftshift(fft2(img));
\mask = fspecial('gaussian',[3 3], r);
M = fft2(mask, size(F,1), size(F,2));
Filtered = M.*F;
nImg = real(ifft2(ifftshift(Filtered)));
end.
1 commentaire
Image Analyst
le 1 Nov 2021
@Habtamu Fanta, I'm not sure how this is an answer. You just introduced a couple of errors (bad characters) into the original poster's code - that's all. It doesn't fix or address either of the two items mentioned by Steve's advisor professor.
Catégories
En savoir plus sur Image Filtering dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!