Description Usage Arguments Details Value See Also Examples
View source: R/modify.operators.R
Match cells of a raster with a kernel
1 |
obj |
[ |
kernel |
[ |
rotate |
[ |
background |
[ |
This is also known as the 'hit-or-miss'-transform.
Wrapper of
rMorph
with blend = 2 and merge = 12.
The cells of a kernel can have the values 0, 1 and NA. The kernel cells with values 0 and 1 are matched accurately in the input raster. The kernel cells with value NA will be ignored.
A RasterLayer
or RasterStack
of the same dimension as
obj
in which all cells that match with the kernel(s) have the kernel
value and all other cells have the value background
.
Other operators to select a subset of cells: rBounded
,
rGreater
, rLess
,
rMask
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | input <- rtRasters$continuous
binarised <- rBinarise(input, thresh = 30)
# match isolated cells
(kIso <- matrix(c(0, 0, 0, 0, 1, 0, 0, 0, 0), 3, 3))
matched <- rMatch(binarised, kernel = kIso)
visualise(matched)
# match all right angled corners
(kCorner <- matrix(c(NA, 1, NA, 0, 1, 1, 0, 0, NA), 3, 3))
matched <- rMatch(binarised, kernel = kCorner, background = 0)
visualise(matched, new = TRUE)
# match north-east facing right angled corners and isolated cells
matched <- rMatch(binarised, kernel = list(kIso, kCorner), rotate = FALSE)
visualise(matched, new = TRUE)
# match endpoints of a skeleton
skeletonised <- rSkeletonise(binarised, background = 0)
(kEnd <- matrix(c(NA, 0, 0, NA, 1, 0, NA, 0, 0), 3, 3))
endpoints <- rMatch(skeletonised, kernel = kEnd, background = 0)
# match triple points (conjunctions) of a skeleton
kConj <- list(matrix(c(NA, 0, 1, 1, 1, NA, NA, 0, 1), 3, 3),
matrix(c(1, NA, 1, NA, 1, NA, NA, NA, 1), 3, 3),
matrix(c(NA, 1, NA, 0, 1, 1, 1, 0, NA), 3, 3))
conjunctions <- rMatch(skeletonised, kernel = kConj, background = 0)
out <- raster::stack(
rBlend(skeletonised, overlay = endpoints),
rBlend(skeletonised, overlay = conjunctions[[1]]),
rBlend(skeletonised, overlay = conjunctions[[2]]),
rBlend(skeletonised, overlay = conjunctions[[3]]))
names(out) <- c("endpoints", "conj1", "conj2", "conj3")
visualise(out)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.