| focal_special {ursa} | R Documentation |
Custom spatial filtering for image
Description
For each band and for each cell, function calculates value using specific matrix of square window. Focal operation of map algebra.
Usage
focal_special(x, type = c("custom", "gaussian", "laplacian", "osisaf",
"hires", "correl", "LoG", "sobel", "sobelG"),
fmask = NULL, size = 3, alpha = 0.5, sigma = (size-1)/4,
cover = 1 - 1e-06, fillNA = FALSE, saveMargin = FALSE, verbose = 0L)
Arguments
x |
Object of class |
type |
Character, which is checked by |
fmask |
Numeric square matrix. Filter mask. If |
size |
Numeric. Diameter of circuled filter mask. Coerced to the nearest odd value not less than original value. |
alpha |
Nimeric. Parameter |
sigma |
Numeric. Parameter |
cover |
Numeric. |
fillNA |
Logical. If |
saveMargin |
Logical. If |
verbose |
Integer of |
Details
Developed under impression from Matlab's "fspecial".
type="custom"
Filter mask (argumentfmask) should be specified manually.type="gaussian"
Gaussian filter. For cascade filtering (sequence of increasing or decreasing windowsize)sigma=(size-1)/4produces the same distribution density relative to window size. Ifsigmais high but notInfthen it is low-pass filter with diameter=sizeof circular focal window.type="laplacian"
Laplacian filter. Onlysize=3makes sence. Anysizeis coerced tosize=3.type="osisaf"
Filter for edge detection. Onlysize=5makes sence. Anysizeis coerced tosize=5. TODO (pl): reference-0.0625 -0.0625 -0.0625 -0.0625 -0.0625 -0.0625 0.1250 0.1250 0.1250 -0.0625 -0.0625 0.1250 0.0000 0.1250 -0.0625 -0.0625 0.1250 0.1250 0.1250 -0.0625 -0.0625 -0.0625 -0.0625 -0.0625 -0.0625type="hires"
Filter for unsharping. Onlysize=3makes sence. Anysizeis coerced tosize=3.-alpha alpha-1 -alpha alpha-1 alpha+5 alpha-1 -alpha alpha-1 -alphatype="correl"
Filter for contrast increasing. Onlysize=3makes sence. Anysizeis coerced tosize=3.alpha^2 -alpha*(1+alpha^2) alpha^2 -alpha*(1+alpha^2) (1+alpha^2)^2 -alpha*(1+alpha^2) alpha^2 -alpha*(1+alpha^2) alpha^2type="LoG"
Laplacian of Gaussian. Filter for edge detection.sigmais used,alphais ignored.type="sobel"
Two-directional Sobel filtering. Onlysize=3makes sence. Anysizeis coerced tosize=3.type="sobelG"
Sobel gradient. Onlysize=3makes sence. Anysizeis coerced tosize=3.
Value
Object of class ursaRaster with the same number of bands as in input raster.
Warning
Laplacian of Gaussian filter (type="LoG") is not implemented clearly due to applying continuous-valued formula to discrete matrix.
Author(s)
Nikita Platonov platonov@sevin.ru
References
TODO(pl): at least reference to 'osisaf'.
See Also
Other focal operations: focal_mean, focal_median, focal_extrem.
Examples
session_grid(NULL)
v <- round(runif(8,min=-1,max=1),3)
customFilter <- matrix(c(v[1:4],-sum(v),v[5:8]),ncol=3)
a <- ursa_dummy(1,mul=4/8,elements=32)
tpList <- eval(formals("focal_special")$type)
res <- c(src=a,as.ursa(bandname=tpList))
for (tp in tpList) {
message(tp)
res[tp] <- focal_special(a,tp,fmask=customFilter,size=11,sigma=1,alpha=0.8
,saveMargin=0,verbose=2L)
}
print(res)
display(res,decor=FALSE)