op <- par(mfcol = c(1, 2))
x <- seq(-10, 10, length.out = 30)
y <- x
f <- function(x, y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
z[is.na(z)] <- 1
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
title( main = "Original")
h <- matrix(c(1, -2, 1, -2, 3, -2, 1, -2, 1), 3, 3)
zf <-filter2(h, z, 'same')
persp(x, y, zf, theta = 30, phi = 30, expand = 0.5, col = "lightgreen")
title( main = "Filtered")
par(op)
Run the code above in your browser using DataLab