
%%% This is a tutorial and exercises for linear visual filters
%%% (receptive fields). It includes:
%%% (1) Examples of constructing visual Gabor filters and
%%% filtering an image.

%%% Read the comments and run the lines of code into matlab.
%%% Type 'help <function_name>' in Matlab window for any
%%% function you would like more information on.
%%% Type 'which <function_name>' in Matlab window for the
%%% location of a file.

%%% OS 2012

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% (1) Visual filters and images
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% (1a) Gabor filters and images

%% Set parameters of sinusoid
sz = 20;
ctr = [round(sz/2+1), round(sz/2+1)];
period = 5;
direction = pi;
phase = 2*pi;
theSine = mkSine(sz, period, direction, 1, phase);
%%% Plot the sinusoid
subplot(2,2,1); showIm(theSine)

%% Make a 2 dimensional Gaussian and plot it
thesig = 2;
theGauss = mkGaussian(sz, thesig, ctr,1);
subplot(2,2,2); showIm(theGauss)

%% Make a Gabor filter, by multiplying a sinusoid with a Gaussian.
theFilt = theSine .* theGauss;
subplot(2,2,3); showIm(theFilt)

%%% 2. Load and filter an image

%% Load an image
im = pgmRead('feynman.pgm');
figure(2); subplot(2,2,1); showIm(im);

%% (1b) Linear response of filter
response = rconv2(im, theFilt); 
figure(2); subplot(2,2,2); showIm(response)

%%% *To do*:
%%% 1. Try making different Gabor filters by varying parameters above
%%% (e.g., direction, period, phase of the grating; and thesig of the Gaussian)
%%% Try reading in different images

