Hi Gianni,

Is it something like this you are looking for?

wgauss <- function(sigma, n=5) {
m <- matrix(nc=n, nr=n)
col <- rep(1:n, n)
row <- rep(1:n, each=n)
x <- col - ceiling(n/2)
y <- row - ceiling(n/2)
# http://en.wikipedia.org/wiki/Gaussian_filter
m[cbind(row, col)] <- 1/(2*pi*sigma^2) * exp(-(x^2+y^2)/(2*sigma^2))
m / sum(m)
}

wgauss(1)
wgauss(2)
wgauss(2, 9)


Robert

On Thu, Feb 23, 2012 at 4:59 AM, gianni lavaredo
<gianni.lavaredo@gmail.com>wrote:

> Dear Researchers,
>
> I have a simple question but I wish to find a clear answer. I wish to test
> several sigma at a 3x3 kernel gaussian lowpass filter. In RASTER library
> there is the following example:
>
> r <- raster(ncols=36, nrows=18, xmn=0)
> r[] <- runif(ncell(r))
> plot(r)
>
> # i find two kernel mask
> gf1=matrix(c(1,2,1,2,4,2,1,2,1), nrow=3)/16
> gf2=matrix(c(2,4,2,4,16,4,2,4,2), nrow=3)/40
>
> rg1 <- focal(r, w=gf1)
> plot(rg1)
> rg2 <- focal(r, w=gf2)
> plot(rg2)
>
> The simple question is How calculate the sigma value of the both masks.
> Furthermore, If I decide a sigma How I can get a mask value?
>
> Thanks in Advance
> Gianni
>
> PS:
> In MATLAB there is a function to determinate hsize (i.e. 3x3) and SIGMA
> value. Is there a similar function improved for RASTER?
>
> Since you mentioned MATLAB - you can take a look at various gaussian
> kernels with different parameters using the fspecial('gaussian', hsize,
> sigma) function, where hsize is the size of the kernel and sigma is, well,
> sigma. Try varying the parameters to see how it changes.
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

