i want to use the terra::focal() with an even sided matrix (e.g. to apply "Roberts cross" edge detection; https://en.wikipedia.org/wiki/Roberts_cross).
However, focal() only accepts windows with odd sides. On the other hand, the focal3D() documentation states "w =window. [...] If you desire to use even sides, you can use an array, and pad the values with rows and/or columns that contain only NAs."
Applying this "trick" for 2D focal does not work:
r <- rast(matrix(rnorm(1000),ncol=100,nrow=100))
robx <- matrix(c(NA,1,0,NA,0,1),nrow=3)
plot(focal(r,w=robx,fun="sum")
while (of course), a 3 by 3 matrix without NAs works:
sobx <- matrix(c(-1,-2,-1,0,0,0,1,2,1) / 4, nrow=3)
plot(focal(r,w=sobx,fun="sum")
Are there any known workarounds? How can i get focal() to accept even sided windows (or at least trick it)?
Cheers.
