predictSegments: Predict class labels for image segments

View source: R/SOptim_RasterOutputs.R

predictSegmentsR Documentation

Predict class labels for image segments

Description

This function uses an input SOptim.Classifier object to predict class labels for train or all segments in the input segmented image.

Usage

predictSegments(
  classifierObj,
  calData,
  rstSegm,
  predictFor = "all",
  filename = NULL,
  verbose = TRUE,
  na.rm = TRUE,
  forceWriteByLine = FALSE,
  ...
)

Arguments

classifierObj

An object of class SOptim.Classifier containing a classification algorithm generated by function calibrateClassifier with option runFullCalibration = TRUE.

calData

An object of class SOptim.CalData generated by function prepareCalData containing calibration data for train segments and the entire image.

rstSegm

A string defining the path to the raster with segment IDs, a SpatRaster object or a SOptim.SegmentationResult object (generated by any segmentation function (check segmentationGeneric).

predictFor

Either option "train" which predicts class labels only for train segments or option "all" which predicts for all existing segments in rstSegm (default: all).

filename

A file name/path used to write the output raster (default: NULL).

verbose

Print comments with function progress? (default: TRUE).

na.rm

Remove NA's? (default: TRUE).

forceWriteByLine

Use memory-safe writing of raster output by line? (default: FALSE). If forceWriteByLine = TRUE, then filename must define a valid file path.

...

Additional arguments for writeRaster function except datatype which is already internally set to 'INT4U'.

Details

By default the function uses the classifier ran with the 'full' dataset (i.e., no train/test splits) for making class label predictions. In case of single-class problems the threshold that maximizes the selected evaluation metric (check evalMetric in calibrateClassifier) is used to dichotomize predictions. For multi-class problems the output class label is set for the one with highest probability value.

Value

An object of class SpatRaster containing the predicted class labels for each image segment. If the file name is defined, the function will write a file containing the output raster. The output data type is INT4U (see datatype for more details) which means negative values for class labels are not valid.


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