function im2 = filterImageUsingFourier(m,fIn,fOut)


% resize to square, its more convenient
s=min(size(m));
m=imresize(m,[s,s]);

% show
m=imageNormalize(m);
subplot(2,2,1);
imshow(m)

% fourier
f=fft2(m);
fs=fftshift(f);

% show fourier
p=imageNormalize(log (abs(fs)+1));
subplot(2,2,2);
imshow(p);

% filter: define areas taken in and thrown out
center = floor(s/2)+1;
rangeIn = center-fIn:center+fIn;
if exist('fOut')
    rangeOut = center-fOut:center+fOut;
else
    rangeOut = [];
end

% copy area of fourier-spectrum: this is the filter !
fsf = zeros(size(fs));
fsf(rangeIn,rangeIn)=fs(rangeIn,rangeIn);
if length(rangeOut) > 0
    fsf(rangeOut,rangeOut)=0;
end

% show filtered spectrum
p=imageNormalize(log(abs(fsf)+1));
subplot(2,2,3);
imshow(p);

% retransform to picture
im2 = ifft2(fftshift(fsf));
im2=imageNormalize(im2);
subplot(2,2,4);
imshow(abs(im2));

% goodbye
return

%-----------------------------
% normalize image to 0 - 1
function p=imageNormalize(p)
    p=im2double(p);
    minp=min(p(:));maxp=max(p(:));
    p=(p-minp)/(maxp-minp);
return
