필터 지우기
필터 지우기

Gaussian mask for low-pass filter in frequency domain.

조회 수: 6 (최근 30일)
Jakub
Jakub 2014년 10월 21일
답변: Image Analyst 2014년 12월 1일
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

채택된 답변

Image Analyst
Image Analyst 2014년 12월 1일
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by