Learn R Programming

sits (version 1.4.1)

sits_segment: Segment an image

Description

Apply a spatial segmentation on a data cube based on a user defined segmentation function. The user defines the tiles of the cube to be segmented and informs the bands and the date to be used. The function applies the segmentation algorithm "seg_fn" to each tile.

Segmentation uses the following steps:

  • use sits_segment to obtain the sf polygons that define the boundary of the segments.

  • use sits_get_data to obtain one time series associated to each segment.

  • use sits_classify to classify the time series associated to the segments.

  • use sits_join_segments to update the class for each segment, based on the time series classification.

  • use plot or sits_view to display the results.

  • The result of sits_join_segments is a list of sf objects with a "class" attribute. Use the functions available in sf for further analysis.

Usage

sits_segment(cube, tiles = NULL, bands = NULL, dates = NULL, seg_fn, ...)

Value

A list of "sf" objects, indexed by tile. Each "sf" object contains the polygons that define the segments.

Arguments

cube

Regular data cube

tiles

Tiles to be segmented

bands

Bands to include in the segmentation

dates

Dates to consider to be segmented

seg_fn

Function to apply the segmentation

...

Other params to be passed to segmentation function

Author

Gilberto Camara, gilberto.camara@inpe.br

Rolf Simoes, rolf.simoes@inpe.br

Felipe Carvalho, felipe.carvalho@inpe.br

Examples

Run this code
if (sits_run_examples()) {
data_dir <- system.file("extdata/raster/mod13q1", package = "sits")
# create a data cube
cube <- sits_cube(
    source = "BDC",
    collection = "MOD13Q1-6",
    data_dir = data_dir
)

# segment the image
segments <- sits_segment(
    cube = cube,
    tile = "012010",
    bands = "NDVI",
    dates = sits_timeline(cube)[1],
    seg_fn = sits_supercells(step = 20)
)
# create a classification model
rfor_model <- sits_train(samples_modis_ndvi, sits_rfor())
# get the average value per segment
samples_seg <- sits_get_data(
    cube = cube,
    samples = segments
)
# classify the segments
seg_class <- sits_classify(
    data = samples_seg,
    ml_model = rfor_model
)
# add a column to the segments by class
sf_seg <- sits_join_segments(
    data = seg_class,
    segments = segments
)
}

Run the code above in your browser using DataLab