Gaussian mask for low-pass filter in frequency domain.
12 views (last 30 days)
Show older comments
Hey i want to do simple low-pass filter in frequency domain with cutoff frequency 0,2. I need to create mask in frequency plane. Here is my code but it is not elegant at all. Since i am using normalized frequency i have to use normalize distance is that right? is there a elegant way to do it without so many loops? i have to do it manually without using fspecial function. Thank you!
[m n]=size(im);
p=m/2;
q=n/2;
d0=0.2;
for i=1:m
for j=1:n
distance(i,j)=sqrt(((i-p)^2+(j-q)^2));
end
end
distance=mat2gray(distance);
for i=1:m
for j=1:n
Hglp(i,j)=(exp(-(distance(i,j))^2/(2*(d0^2))));
end
end
0 Comments
Accepted Answer
Image Analyst
on 1 Dec 2014
fspecial() is the more elegant and better way but since you can't use that you can either use meshgrid() and do a vectorized solution, or do the double nested for loops like you're doing. Your way is fine - it's easy to understand, unlike the meshgrid way, and since your loops are small, I'd stick with that.
Just remember that the Fourier transform puts the origin at the 4 corners and your way is not doing a low pass filter unless you've called fftshift() to get the Hglp array to put the origin at the center of the array. VERY IMPORTANT! Or else you're doing a high pass filter instead of a low pass filter!
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!