% Filtering_2D
% Author C. Prati
% February 17, 2020

clear
close all
% IF OCTAVE %%%
%pkg load image
%pkg load signal
%%%%%%%%%%%%%%%
%--------------------------------------------------
% 1
% Let us load a 2D image (e.g.in jpeg format)
% 
%--------------------------------------------------

IMAGE=imread('gatto.jpg');
%IMAGE=imread('GEMSclass.jpg');
X=(IMAGE(:,:,1));
%X=(IMAGE(:,:,1));
figure(1)
imagesc(X)
colormap gray
axis('image')
title('original')
pause



%--------------------------------------------------
% 2
% Let us generate a 2D low-pass filter by using the 
% fir1 Matlab function in 1D and then the function ftrans2 
% which produces filters that are approximately circularly
% The normalized "radial" cut-off frequency is fc=0.1 
% The filter length is N=35
%--------------------------------------------------
fc=0.1;
Wc=fc*2;
N=34;
hLP=fir1(N,Wc);
hLP_2D=ftrans2(hLP);
figure(2)
imagesc(hLP_2D)
colormap jet
axis('image')
pause

%--------------------------------------------------
% 3
% Let us apply the 2D low-pass filter to the original image 
%--------------------------------------------------

XLP=conv2(X,hLP_2D,'same');
figure(2)
imagesc(XLP)
colormap gray
axis('image')
title('LP filtered')
pause

%--------------------------------------------------
% 4
% Let us generate a 2D high-pass filter by using the 
% fir1 Matlab function in 1D and then the function ftrans2 
% which produces filters that are approximately circularly
% The normalized "radial" cut-off frequency is fc=0.05 
% The filter length is N=35
%--------------------------------------------------
fc=0.05;
Wc=fc*2;
N=34;
hHP=fir1(N,Wc,'high');
hHP_2D=ftrans2(hHP);
figure(2)
imagesc(log(abs(hHP_2D)))
colormap jet
axis('image')
pause

%--------------------------------------------------
% 5
% Let us apply the 2D high-pass filter to the original image 
%--------------------------------------------------

XHP=conv2(X,hHP_2D,'same');
figure(2)
imagesc(XHP)
colormap gray
axis('image')
title('HP filtered')



