s-news
[Top] [All Lists]

Re: Gaussian kernel

To: Catalina Mesina <cmesina@cs.vu.nl>
Subject: Re: Gaussian kernel
From: <ripley@stats.ox.ac.uk>
Date: Thu, 24 Oct 2002 12:38:57 +0100 (BST)
Cc: S-news list <s-news@lists.biostat.wustl.edu>
In-reply-to: <3DB7D2B9.907B02C2@cs.vu.nl>
On Thu, 24 Oct 2002, Catalina Mesina wrote:

> Hello Dear S+ users:
>
>
> I would like to make a Gaussian kernel to smooth(convolv) some 2D-images
> something that in matlab cab be wrote:
>
> % 2d Gaussian kernel
> Dim = [20 20];
> fineness = 0.1;
> [x2d,y2d] = meshgrid(-(Dim(2)-1)/2:fineness:(Dim(2)-1)/2,...
>                -(Dim(1)-1)/2:fineness:(Dim(1)-1)/2);
> gf    = exp(-(x2d.*x2d + y2d.*y2d)/(2*sig*sig));
> gf    = gf/sum(sum(gf))/(fineness^2);
>
>
> How can I make this grid of points and the matrix of results without using 
> "for"?

I believe you are looking for expand.grid() to replace meshgrid.

The Gaussian kernel is a product kernel, so this is a very inefficient way
to do the smoothing.  Do a univariate Gaussian smoothing in the x
direction then one in the y direction.  And there is code to do Gaussian
smoothing around, or you could write it yourself using filter().

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>