View source: R/SOptim_GetTrainData.R
getTrainData | R Documentation |
An ancillary function used to generate training data for classification
getTrainData(
x,
rstSegm,
useThresh = TRUE,
thresh = 0.5,
na.rm = TRUE,
dup.rm = TRUE,
minImgSegm = 30,
ignore = FALSE,
tiles = NULL
)
## Default S3 method:
getTrainData(
x,
rstSegm,
useThresh = TRUE,
thresh = 0.5,
na.rm = TRUE,
dup.rm = TRUE,
minImgSegm = 30,
ignore = FALSE,
tiles = NULL
)
## S3 method for class 'SpatRaster'
getTrainData(
x,
rstSegm,
useThresh = TRUE,
thresh = 0.5,
na.rm = TRUE,
dup.rm = TRUE,
minImgSegm = 30,
ignore = FALSE,
tiles = NULL
)
## S3 method for class 'character'
getTrainData(
x,
rstSegm,
useThresh = TRUE,
thresh = 0.5,
na.rm = TRUE,
dup.rm = TRUE,
minImgSegm = 30,
ignore = FALSE,
tiles = NULL
)
x |
Input train data used for classification. The input can be a |
rstSegm |
A path or a |
useThresh |
Use threshold to filter training data for multi-class? (default: TRUE; not used for points). |
thresh |
A threshold value defining the minimum proportion of the segment ]0, 1] that
must be covered by a certain class to be considered as a training case. This threshold will
only apply if |
na.rm |
Remove NA's? (default: TRUE). Only used if |
dup.rm |
Remove duplicate values? (default: TRUE; see details). Only used if |
minImgSegm |
Minimum number of image segments/objects necessary to generate train data. |
ignore |
If set to TRUE then train data may contain one single class. This is useful in cases where sample units contain only positive or negative train cases. Also applies if the threshold value is employed. In this case if no positive cases are generated then negatives will be returned (default: FALSE). |
tiles |
An object of class |
In some cases, depending on the type of input training data or the output of the segmentation, duplicate segment IDs (SID) may occur for different class(es) meaning that a given segment may have more than one training class. In those cases dup.rm should be set to TRUE (default).
Raster data (in x
and rstSegm
) will be coerced to integer values before performing
cross-tabulations to evaluate the percent coverage.
A two-column data frame with segment IDs (column "SID") and the corresponding train class (column "train").
Train raster data must contain at least two categories, coded as integers:
- 0 and 1 for "single-class" (with 1's being the feature of interest);
- or 1,2,...,n for "multi-class".
To produce valid train data, the image segmentation produce must generate at least 30 unique segments (or objects)
library(terra)
rstSegm <- rast(nrows=100, ncols=100, xmin=0, xmax=100,ymin=0,ymax=100,res=1)
km <- kmeans(xyFromCell(rstSegm, 1:ncell(rstSegm)),100,iter.max = 100)
values(rstSegm) <- km$cluster
rstTrain <- rast(nrows=100, ncols=100, xmin=0, xmax=100,ymin=0,ymax=100,res=1)
km <- kmeans(xyFromCell(rstTrain, 1:ncell(rstTrain)),5,iter.max = 100)
values(rstTrain) <- km$cluster
getTrainData(rstTrain, rstSegm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.