convert band pass to band reject

5 views (last 30 days)
i've this code for band pass filter ,any one can convert it to band reject filter ??
% Bandpass Butterworth Filter
clearall;
closeall;
clc
micro = imread('grass2.jpg');
micro = double(micro);
[nx ny] = size(micro);
nx
ny
u = micro;
micro = uint8(u);
imwrite(micro,'grass5.jpg');
fftu = fft2(u,2*nx-1,2*ny-1);
fftu = fftshift(fftu);
subplot(2,2,1)
imshow(micro,[]);
subplot(2,2,2)
fftshow(fftu,'log')
% Initialize filter.
filter1 = ones(2*nx-1,2*ny-1);
filter2 = ones(2*nx-1,2*ny-1);
filter3 = ones(2*nx-1,2*ny-1);
n = 4;
fori = 1:2*nx-1
forj =1:2*ny-1
dist = ((i-(nx+1))^2 + (j-(ny+1))^2)^.5;
% Use Butterworth filter.
filter1(i,j)= 1/(1 + (dist/120)^(2*n));
filter2(i,j) = 1/(1 + (dist/30)^(2*n));
filter3(i,j)= 1.0 - filter2(i,j);
filter3(i,j) = filter1(i,j).*filter3(i,j);
end
end
% Update image with passed frequencies.
fil_micro = fftu + filter3.*fftu;
subplot(2,2,3)
fftshow(filter3,'log')
fil_micro = ifftshift(fil_micro);
fil_micro = ifft2(fil_micro,2*nx-1,2*ny-1);
fil_micro = real(fil_micro(1:nx,1:ny));
fil_micro = uint8(fil_micro);
subplot(2,2,4)
imshow(fil_micro,[])

Accepted Answer

Image Analyst
Image Analyst on 16 Jul 2013
Just invert the filter. Make filter3 = 1-filter3. Try that.
  1 Comment
mecheal
mecheal on 16 Jul 2013
do u trace my code ? is it correct ? how can i identify the frequencies that included in the rejected band ??

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!