from
Bandpass filter for image processing
by Gholamreza (Shahab) Anbarjafari
A simple application of FFT2 for an image to simulate the effect of bandpass filter
|
| BPF_Image(c_off1,c_off2)
|
% This function is a very simple application of FFT2 for an image to
% simulate the effect of bandpass filter with two cut off frequencies. One
% can easily modify the programme to do the processes for different images,
% and even implement highpass and lowpass filter.
% This programme has been written in Spring 2007, as part of my Image
% Processing course offered by Assoc. Prof. Dr. Hasan Demirel.
% You are free to use this code for academic purposes without referring to me,
% Gholamreza % Anbarjafari (Shahab).
% The inputs of the function are cutoff frequencies, where as c_off1<c_off2
% e.g. c_off1=50 and c_off2=150.
% (c) Gholamreza Anbarjafari (Shahab): shahab.jafari@emu.edu.tr
% (c) Hasan Demirel: hasan.demirel@emu.edu.tr
% http://faraday.ee.emu.edu.tr/hdemirel , http://faraday.ee.emu.edu.tr/shahab
function BPF_Image(c_off1,c_off2)
clc
clear memory
ima=rgb2gray(imread('Ipek.jpg'));
ima = double(ima);
figure
subplot(121)
imshow(ima,[ ]);
title('Original image');
imafft = fftshift(fft2(fftshift(ima)));
s = size(ima);
ma=max(max((imafft)));
maxr = 0.5*sqrt(s(1)^2+s(2)^2);
cutoff1 = maxr*c_off1;
cutoff2 = maxr*c_off2;
c=1;
for i = 1 : s(1)
for j = 1 : s(2)
r = sqrt((i-1-s(1)/2)^2+(j-1-s(2)/2)^2);
if ( r < 50)
z(i,j) = 0;
else
if ( r > 150)
z(i,j) = 0;
else
z(i,j) =255;
end
end
end
end
subplot(122)
imafft=imafft.*z/255;
ima_out = fftshift(ifft2(fftshift(imafft)));
ima_out =ima_out-ima;
imshow(uint8(abs(ima_out)),[ ]);
title('Filtered image (Ideal)');
figure
imshow(log(1+abs(z)),[ ]);
title('Filtered');
|
|
Contact us at files@mathworks.com