segmentation_GRASS_RG: GRASS Region Growing image segmentation

View source: R/SOptim_SegmentationFunctions.R

segmentation_GRASS_RGR Documentation

GRASS Region Growing image segmentation

Description

A function providing CLI access to GRASS Region Growing image segmentation algorithm and optimize parameters using genetic algorithms. To use this function, image features used in segmentation must be imported into a GRASS database (importToGRASS).

Usage

segmentation_GRASS_RG(
  x,
  GRASS.path = "grass",
  GRASS.inputRstName,
  GRASS.GISDBASE,
  GRASS.LOCATION_NAME = "demolocation",
  GRASS.MAPSET = "PERMANENT",
  outputSegmRst = NULL,
  Threshold = NULL,
  MinSize = NULL,
  memory = 1024,
  iterations = 20,
  verbose = TRUE
)

Arguments

x

A vector with size two defining the values of segmentation parameters optimized by GA:

  • [1] threshold (float) - difference threshold between 0 and 1. Threshold: 0 merges only identical segments; threshold: 1 merges all.

  • [2] minimum number of cells in a segment (integer) - the final step will merge small segments with their best neighbor; options: 1-100000 (default: 1).

If you are using this function outside an optimization context it is better to directly define the segmentation parameters in Threshold and MinSize.

GRASS.path

Defines the initialization path to GRASS .bat file for windows (for example: 'C:/GRASS/grass70') or the .sh or .py file for Linux (usually this should be set to '/usr/bin/grass'). The default is "grass70" which assumes that GRASS is in the path environmental variables and version 7.0.x (which may not be appropriate in most cases and therefore this parameter should be set explicitly).

GRASS.inputRstName

Name of the raster dataset that will be segmented (typically a multi-layered raster dataset with segmentation features in each band).

GRASS.GISDBASE

Name of GRASS GIS database.

GRASS.LOCATION_NAME

Name of GRASS location name (default: "demolocation").

GRASS.MAPSET

Name of GRASS mapset (default: "PERMANENT").

outputSegmRst

A path to the output segmented image exported by GRASS r.out.gdal. The output file can be in any of GDAL formats (default: NULL; in this case the segmenter will internally determine a temporary output folder and file path inside the working directory).

Threshold

Difference threshold between 0 and 1. Threshold: 0 merges only identical segments; threshold: 1 merges all

MinSize

Minimum number of cells in a segment (integer) - the final step will merge small segments with their best neighbor

memory

Memory used to run i.segment (default: 1024Mb).

iterations

Maximum number of iterations (default: 20).

verbose

Output messages? (default: TRUE)

Details

This function uses a batch file defining the batch job (GRASS_BATCH_JOB) and starts GRASS with the appropriate parametrization. The i.segment command is used to run the segmentation. The similarity calculation method uses the default value ("euclidean"). See more info at GRASS manual pages online: i.segment at https://grass.osgeo.org/grass72/manuals/i.segment.html Access to GRASS GIS manuals https://grass.osgeo.org/documentation/manuals/

Value

A list object containing output file paths resulting from the segmentation run. These files will be cleaned after each GA iteration.


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