% program to illustrate convolution with a gaussian function
% take Lenna image and convolve with a gaussian

% need to be in directory c:\jl\4F8_ImageProcessing\ImageProcessing1\ImageProc1Mat\ImageProc1Demo

% run convolution_demo
clear,clc,close all,home

load lenna256.mat

% array x now contains the Lenna image

% display lenna image
figure(1);
grayimage(x);
pause;

% now generate Gaussian image

disp('Use 64 data points and variance=20');
N=input('Number of samples in horizontal and vertical direction (even), N = ');
var=input('Variance of gaussian bell = ');
N1=N/2;
vec1=(-N1:N1-1)';
for i=1:N
  for j=1:N
    g(i,j) = 256*exp(-((i-(N1+1))^2+(j-(N1+1))^2)/var);
  end
end
figure(2);
grayimage(g);
pause;
%  now convolve the gaussian and Lenna


Y = conv2(x,g);
figure(3);
grayimage(Y);

% shows the blurring produced by this particular convolution -- in
% this case the gaussian is an example of a point spread function
