Bandreject filtering on an image

How do i create a bandreject filter which i want to apply on an image ??
I want to create a bandrejectFilter of radius 10 and want to apply on an image
I know the code that i have written is wrong.Can somebody please help me with it
% Use Bandreject filter
[m,n]=size(I);
u0=256; % Cutoff frequency
u=0:m-1
v=0:n-1
if D(u,v)<266
H(u,v)==1
else H(u,v)=0
end
if D(u,v)>266
H(u,v)=1
else H(u,v)=0
end

 Accepted Answer

Image Analyst
Image Analyst on 12 Mar 2014
I don't understand that at all. All you're doing it some kind of strange way of intensity thresholding. Do you want to threshold a range of intensities or do a spatial frequency filter?
If you want a band reject spatial frequency filter, what I would do is to take the FFT, then call fftshift, then multiply by a black ring to zero out the stuff in the designated frequency range, then unshift and inverse fft.

4 Comments

ok sorry about the previous code but i'm new in matlab hence i made a lot of mistakes
Here's the improved code
d0=centre frequency of the image
I want to reject all the frquencies betwenn 276 and 236 hence i added and subtracted 20
F1 is fftshift on fft2 of I
% Use ideal bandreject filter
[m,n]=size(I)
filter=ones(m,n);
d0=256;
for i=1:m-1
for j=1:n-1
d1=((i-m)^2+(j-n)^2)^.5;
if d1<=d0+20
if d1>=d0-20
filter(i,j)=0;
else
filter(i,j)=1;
end
end
end
end
G=filter.*F1;
g1=abs(ifft2(G));
figure(1),imshow(g1,[])
Is this code correct ??
No. For one thing the circle is centered at the corner instead of the middle. Also filter is the name of a built in function so you need to choose another name. And it was initialized to 1 so you don't need to do that again in the if block. Finally you can combine the two ifs into one
if d0-20 < d1 && d1 << d0+20
Of course you could vectorize it by looking at the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
Thank you very much.Finally got it
Please upload the final code

Sign in to comment.

More Answers (0)

Tags

Asked:

ram
on 12 Mar 2014

Commented:

on 15 Apr 2019

Community Treasure Hunt

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

Start Hunting!