label: Labelling of unique patches and detection of percolation.

Description Usage Arguments Details Value See Also Examples

View source: R/label.R

Description

Label each patch with a number in a binary matrix

percolation() detects whether percolation occurs in the matrix (i.e. a patch has a width or a height equal to the size of the matrix)

Usage

1
2
3
4
label(mat, nbmask = matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0), ncol = 3),
  wrap = FALSE)

percolation(mat, nbmask = matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0), ncol = 3))

Arguments

mat

A binary matrix

nbmask

a "neighboring mask": a matrix with odd dimensions describing which cells are to be considered as neighbors around a cell (see examples).

wrap

Whether to wrap around lattice boundaries ('TRUE'/'FALSE'), effectively using periodic boundaries.

Details

The label function "labels" the patches of a binary (TRUE/FALSE) matrix. It returns a matrix of similar height and width, with integer values representing the ID of each unique patch (contiguous cells). Empty cells are labeled as NA.

Value

A matrix containing ID numbers for each connected patch. Default parameters assume 4-cell neighborhood and periodic boundaries. The distribution of patch sizes is returned as the attribute "psd" and the percolation status as "percolation" (whether a TRUE patch has a width or height equal to the size of the matrix).

See Also

patchsizes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
data(forestgap)

par(mfrow=c(1, 2))
rmat <- matrix(rnorm(100) > .1, ncol = 10)
image(rmat)
image(label(rmat))

# With 8-way neighborhood mask and no wrapping around borders
nbmask8 <- matrix(c(1,1,1,
                    1,0,1,
                    1,1,1), ncol=3)
image(label(rmat, nbmask8, wrap = FALSE))

spatialwarnings documentation built on Jan. 27, 2018, 3:01 a.m.