getTrainRasterSegments: Generate a raster data set with train segments

View source: R/SOptim_RasterOutputs.R

getTrainRasterSegmentsR Documentation

Generate a raster data set with train segments

Description

An utility function used to create a raster dataset containing train segments for a given segmentation solution and a train raster.

Usage

getTrainRasterSegments(
  trainData,
  rstSegm,
  filename = NULL,
  useThresh = TRUE,
  thresh = 0.5,
  na.rm = TRUE,
  dup.rm = TRUE,
  minImgSegm = 30,
  ignore = FALSE,
  verbose = TRUE,
  ...
)

Arguments

trainData

Input train data. The input can be a SpatRaster, an integer vector (containing raster data after using values function) or a character string with a path to a raster layer. If trainData is an integer vector then it should have a length equal to the number of pixels in rstSegm.

rstSegm

A path or a SpatRaster object containing the outputs of a segmentation algorithm with each object/segment identified by an integer index.

filename

A filename/path used to write the output raster (default: NULL)

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 x is a SpatRaster which means you are using train areas/pixels. If you are running a "single-class" problem then this threshold only applies to the class of interest (coded as 1's). Considering this, if a given segment has a proportion cover of that class higher than thresh then it is considered a train case. In contrast, for the background class (coded as 0's), only segments/objects totaly covered by that class are considered as train cases. If you are running a "multi-class" problem then thresh is applied differently. First, the train class is determined by a majority rule then if that class covers more than the value specified in thresh this case is kept in train data otherwise it will be filtered out. See also useThresh.

na.rm

Remove NA's? (default: TRUE). Only used if x is a SpatialPointsDataFrame object.

dup.rm

Remove duplicate values? (default: TRUE; see details). Only used if x is a SpatialPointsDataFrame object.

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).

verbose

Print comments with function progress? (default: TRUE)

...

Additional options passed to writeRaster function. The option datatype is already internally set to INT2U.

Value

A SpatRaster object with train segments.


joaofgoncalves/SegOptim documentation built on Feb. 5, 2024, 11:10 p.m.