rMorph: Morphologically modify a raster

Description Usage Arguments Details References See Also


Morphologically modify a raster


rMorph(obj, kernel = NULL, blend = NULL, merge = NULL,
  rotate = TRUE, strictKernel = TRUE, background = NULL)



The object to modify.


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


identity, equal, lower, greater, plus, minus, product; see Details.


min, max, all, any, sum, mean, median, sd, cv, one, zero, na; see Details.


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




the value any cell with value NA should have.


The morphC function (internal) is the basis of many modify operations in rasterTools and rMorph exposes a fully functional interface of this C++ function. The morphC function iteratively goes through each pixel of a raster (obj) and compares the kernel with the raster at that location. The result of this comparison depends on the arguments blend and merge:

The following functions are defined for blend:

  1. identity: the value of obj where kernel is not NA.

  2. equal: the value 1 where obj and kernel are equal, otherwise the value 0.

  3. lower: the values of obj that are lower than kernel, otherwise 0.

  4. greater: the values of obj that are greater than kernel, otherwise 0.

  5. plus: the values of obj added to the values of kernel.

  6. minus: the values of kernel subtracted from the values of obj.

  7. product: the product of the values of obj and kernel.

The following functions are defined for merge:

  1. min: the minimum value.

  2. max: the maximum value.

  3. all: the value 1 if all non-NA values are not 0, otherwise 0.

  4. any: the value 1 if any of the non-NA values are not 0, otherwise 0.

  5. sum: the sum of all non-NA values.

  6. mean: the mean of all non-NA values.

  7. median: the median of all non-NA values.

  8. sd: the standard deviation of all non-NA values.

  9. cv: the coefficient of variation of all non-NA values.

  10. sumNa: if the sum of all values is greater than 0 than this sum, otherwise NA.


Credit for the original idea/architecture of the C++ part of this function goes to Jon Clayden (R::mmand). The functionality has been slightly extended here.

See Also

Other operators to morphologically modify a raster: rDilate, rErode

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