function w = gaussian_smoothing ( n, v )

%*****************************************************************************80
%
%% GAUSSIAN_SMOOTHING computes a Gaussian smoothing template.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    06 April 2011
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the "diameter" of the template, that is, the
%    number of pixels along a row or column of the window around the
%    central pixel.  Normally, N is odd.
%
%    Input, real V, the variance of the Gaussian smoothing.  A variance
%    of 1 is typical.  Larger values tend to emphasize data away from the
%    central pixel, while smaller values tend to emphasize the center.
%
%    Output, real W(N,N), the Gaussian smoothing template, a matrix of
%    coefficients that can be used to weight the pixel values around the
%    center pixel to come up with a new center pixel value.
%
  c = floor ( n / 2 ) + 1;

  for j = 1 : n
    for i = 1 : n
      w(i,j) = exp ( - ( ( i - c )^2 + ( j - c )^2 ) / ( 2 * v );
    end
  end
%
%  Normalize W so that the entries sum to 1.
%
  s = sum ( sum ( w ) );
  w = w / s;

  return
end
