Fourier transform (filtering)
(i) Perform low pass filtering in the frequency domain. Write and m-file lowfft.m which does this operation.
lowfft.m
function lowfft
im=imread('class_f.png');
imd=double(im);FI=fft2(imd);
phase=angle(FI);
amplitude=abs(FI);
figure;imshow(log(amplitude),[]);
figure;imshow(phase,[]);
%Where is the energy concentrated? where is low frequency in that spectrum?
help fftshift
figure;imshow(log(fftshift(amplitude)),[]);
figure;imshow(fftshift(phase),[]);
%Where is the energy concentrated? Where is the low frequency in that spectrum?
FIc=fftshift(FI);
amplitude=abs(FIc);
figure;imshow(log(amplitude),[]);
[h w]=size(FIc);
w2=uint8(w/2)
h2=uint8(h/2)
s=50;
mask=zeros(h,w);
mask(h2-s:h2+s,w2-s:w2+s)=1;
figure;imshow(mask,[]);
%What is the role of the box filter here?
FFIc=FIc.*mask;
phase=angle(FFIc);
amplitude=abs(FFIc);
figure;imshow(log(amplitude),[]);
figure;imshow(phase,[]);
FFI=ifftshift(FFIc);
RI=ifft2((FFI));
figure;
imshow(real(RI),[]);
%What happens when you apply the mask filer?
%Where do the artifacts come from?
(ii) Perform high pass filtering in the frequency domain. Write and m-file highfft.m which does this operation.
replace the mask by
mask=ones(h,w);
mask(h2-s:h2+s,w2-s:w2+s)=0;
(iii) Filter the image for different values of parameter s.
What happens when you vary the size of the box filter?