library(terra)
r <- rast(nrows=500, ncols=500, xmin=571823, xmax=616763,
ymin=4423540, ymax=4453690)
crs(r) <- "epsg:9001"
r[] <- runif(ncell(r), 1000, 2500)
r <- focal(r, focalMat(r, 150, "Gauss") )
r.inv <- raster.invert(r)
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
plot(r, main="original raster")
plot(r.inv, main="inverted raster")
par(opar)
Run the code above in your browser using DataLab