oneHotEncode | R Documentation |
Splits a categorical raster layer (or a vector) into a multilayer raster (or matrix).
oneHotEncode(img, classes, background = 0, foreground = 1, na.rm = FALSE, ...)
img |
SpatRaster or integer/numeric vector containing multiple classes |
classes |
integer: vector of classes which should be extracted |
background |
integer: background value (default = 0) |
foreground |
integer: foreground value (default = 1) |
na.rm |
logical: if |
... |
further arguments passed to writeRaster. Ignored if img is not a SpatRaster, but a numeric/integer vector or matrix |
A SpatRaster with as many layers as there are classes. Pixels matching the class of interest are set to 1, backround values by default are set to 0 (see background argument)
sc <- unsuperClass(rlogo, nClasses = 3)
## one-hot encode
sc_oneHot <- oneHotEncode(sc$map, classes = c(1,2,3))
## check results
sc_oneHot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.