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
|