rMatch: Match cells of a raster with a kernel

Description Usage Arguments Details Value See Also Examples

Description

Match cells of a raster with a kernel

Usage

1
rMatch(obj, kernel = NULL, rotate = TRUE, background = NULL)

Arguments

obj

[RasterLayer(1)]
The object to modify.

kernel

[matrix(.) | list(.) thereof]
scan the raster with this kernel (default is a 3 by 3 cells diamond kernel).

rotate

[logical(1)]
should the kernel be applied for all possible rotations (TRUE, default) or should the kernel be used as is (FALSE)?

background

[integerish(1)]
the value any cell with value NA should have.

Details

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.

Value

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.

See Also

Other operators to select a subset of cells: rBounded, rGreater, rLess, rMask

Examples

 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)

EhrmannS/rasterTools documentation built on May 28, 2019, 8:24 a.m.