contagpixelgrid: Pixel Adjacency Contagion

View source: R/contagpixelgrid.R

contagpixelgridR Documentation

Pixel Adjacency Contagion


Function for calculating the classic pixel-adjacency contagion landscape metric from a binary map (O'Neill, 1988).


contagpixelgrid(xi, obswin, normalise = FALSE)

adjacency(xi, obswin = NULL)



A raster binary map (as an im object) or as a foreground set (as an owin object). In the latter case the observation window, obswin, must be supplied. See lacunaritycovariance-package for details. If xi is an owin object it must be of mask type.


If xi is an owin object then obswin is an owin object that specifies the observation window.


If TRUE will divide result by 2 ln(2) and add 1 to make contagion between 0 and 1 for all binary maps.


The unnormalised contagion landscape metric of categorical map is defined as

∑_i ∑_j Qij ln(Qij),

where Qij is the probability of randomly selected adjacent pixels being in class i and class j respectively, and m is the number of classes.

Here m = 2 as xi is a binary map and we have defined 'adjacent' pixels using the 4-neighbourhood regime.

Contagion is calculated from an adjacency matrix created using the function adjacency. The adjacency matrix is a 2 by 2 table containing the number of pairs of neighbouring pixels (where order matters) such that:

Second pixel in xi Second pixel not in xi
First pixel in xi - -
First pixel not in xi - -


The computed pixel-adjacency contagion value. If normalise is TRUE then the value will be between 0 and 1. Otherwise the value will be negative.


  • contagpixelgrid: Pixel-adjacency contagion landscape metric of a binary map.

  • adjacency: Calculates the adjacency matrix used in the pixel contagion


Will fail if map is either all foreground or all background.


O'Neill, R.V., Krummel, J.R., Gardner, R.H., Sugihara, G., Jackson, B., DeAngelis, D.L., et al. (1988) Indices of landscape pattern. Landscape Ecology, 1, 153-162.


xi <- heather$coarse
obswin <- owin(xrange = c(0,7),yrange=c(0,16))
adjmat <- adjacency(xi,obswin)
pixeladjcontagion <- contagpixelgrid(xi,obswin)

lacunaritycovariance documentation built on March 18, 2022, 5:20 p.m.