Title: Metrics for Assessing Segmentation Accuracy for Geospatial Data
Version: 0.3.0
Description: A system that computes metrics to assess the segmentation accuracy of geospatial data. These metrics calculate the discrepancy between segmented and reference objects, and indicate the segmentation accuracy. For more details on choosing evaluation metrics, we suggest seeing Costa et al. (2018) <doi:10.1016/j.rse.2017.11.024> and Jozdani et al. (2020) <doi:10.1016/j.isprsjprs.2020.01.002>.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Imports: magrittr, graphics, units
Suggests: classInt, dplyr, testthat (≥ 3.0.0)
Depends: R (≥ 2.10), sf
BugReports: https://github.com/michellepicoli/segmetric/issues
URL: https://michellepicoli.github.io/segmetric/
NeedsCompilation: no
Packaged: 2023-01-10 12:12:54 UTC; araujopicoli
Author: Rolf Simoes ORCID iD [aut], Alber Sanchez ORCID iD [aut], Michelle Picoli ORCID iD [aut, cre]
Maintainer: Michelle Picoli <mipicoli@gmail.com>
Repository: CRAN
Date/Publication: 2023-01-10 12:30:02 UTC

segmetric

Description

Metrics for assessing segmentation accuracy for geospatial data.

Purpose

The segmetric package provides a set of metrics for the segmentation accuracy assessment (or evaluation) of geospatial data. It includes more than 20 metrics used in the literature for spatial segmentation assessment (Van Rijsbergen, 1979; Levine and Nazif, 1982; Janssen and Molenaar, 1995; Lucieer and Stein, 2002; Carleer et al., 2005; Moller et al., 2007; van Coillie et al., 2008; Costa et al., 2008; Weidner, 2008; Feitosa et al., 2010; Clinton et al. 2010; Persello and Bruzzone, 2010; Yang et al., 2014; and Zhang et al., 2015).

Extensions

The segmetric package is extensible and provides a set of functions to ease the implementation of new metrics. See ?sm_reg_metric() to find how new metrics are implemented.

Contributions

Contribution to this package could be done at segmetric's page on GitHub: https://github.com/michellepicoli/segmetric.

Author(s)

Maintainer: Michelle Picoli mipicoli@gmail.com (ORCID)

Authors:

References

  1. New phytologist, 11(2), pp.37-50. doi: 10.1111/j.1469-8137.1912.tb05611.x

  1. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pp. 658-666.

See Also

Useful links:


Database of metrics functions

Description

These functions are used to register new metrics in the segmetric database.

Usage

.db_list()

.db_set(key, value)

.db_del(key)

.db_get(key)

sm_list_metrics()

sm_new_metric(
  fn,
  fn_subset,
  name = "",
  optimal = 0,
  summarizable = TRUE,
  description = "",
  reference = ""
)

sm_reg_metric(metric_id, entry)

sm_unreg_metric(metric_id)

sm_desc_metric(metric_id)

Arguments

fn

A function that receives a segmetric object and returns the metric values.

fn_subset

A function that returns a subset.

name

A character containing the metric name (Defaults to "").

description

A character containing a description of the metric (Defaults to "").

reference

A character with the reference to a scientific literature describing the metric.

metric_id

A character value containing a unique metric identification.

entry

A metric_entry object returned by new_metric() function.

Value

Examples

sm_reg_metric(
    metric_id = "Example",
    entry = sm_new_metric(
        fn = function(m, ...) {
            sm_area(sm_ytilde(m)) / 
                sm_area(sm_ref(m), order = sm_ytilde(m))
        },
        fn_subset = sm_ytilde,
        name = "Metric name example",
        description = paste("Values range from A to B.",
                            "Optimal value is C"),
        reference = "Author (Year)"
    ))

sm_desc_metric("Example")
sm_list_metrics()


General functions

Description

These functions manipulate segmetric objects.

Usage

sm_area(s, order = NULL)

sm_centroid(s, order = NULL)

sm_distance(s1, s2)

sm_intersection(s1, s2, touches = TRUE)

sm_subset_union(s)

sm_rbind(...)

sm_apply_group(x, groups, fn, ...)

sm_summarize_group(x, groups, fn, ...)

sm_norm_left(x, y)

sm_norm_right(x, y)

sm_options(..., digits = NULL)

Arguments

s, s1, s2

Either a ref_sf, a seg_sf, or a subset_sf object (inherited from sf).

order

A subset_sf. This argument arranges the returned values according to the object passed here.

touches

A logical. Is the border part of the intersection?

...

For sm_rbind(), a set of subset_sf objects to be merged.

x, y

A numeric values (e.g. areas, lengths) to compute metrics.

groups

A group identifier vector used to aggregate a metric for each group.

fn

A function to aggregate a metric for a group.

digits

An integer indicating how many digits used to round metric values.

Value


Metric functions

Description

The sm_compute() computes a given metric (metric_id parameter) from segmentation objects. It compares the reference to the segmentation polygons using a metric.

A list with all supported metrics can be obtained by sm_list_metrics() (see Details for more information).

The sm_metric_subset() returns the subset used to compute the metrics in segmetric object.

Usage

sm_compute(m, metric_id, ...)

sm_metric_subset(m, metric_id = NULL)

Arguments

m

A segmetric object.

metric_id

A character vector with metrics id to be computed.

...

Any additional argument to compute a metric (see Details).

Details

Value

Return a numeric vector with computed metric.

References

A complete list of cited references is available in ?segmetric.

See Also

sm_list_metrics()

Examples

# load sample datasets
data("sample_ref_sf", package = "segmetric")
data("sample_seg_sf", package = "segmetric")

# create segmetric object
m <- sm_read(ref_sf = sample_ref_sf, seg_sf = sample_seg_sf)

# compute AFI metric and summarize it
sm_compute(m, "AFI") %>% summary()

# compute three metrics and summarize them
sm_compute(m, c("AFI", "OS1", "US2")) %>% summary()

# compute OS1, F_measure, and US2 metrics using pipe
m <- sm_compute(m, "OS1") %>%
  sm_compute("F_measure") %>%
  sm_compute("US2")

# summarize them
summary(m)


Plot function

Description

Plot a segmetric map according to the parameter type:

Usage

## S3 method for class 'segmetric'
plot(
  x,
  type = "base",
  ...,
  title = NULL,
  layers = c("ref_sf", "seg_sf"),
  background = "#FFFFFF",
  ref_color = "#FF00009F",
  ref_fill = "#FFFFFF00",
  ref_label = "reference",
  ref_size = 2,
  ref_symbol = 2,
  seg_color = "#0000009F",
  seg_fill = "#FFFFFF00",
  seg_label = "segment",
  seg_size = 1,
  seg_symbol = 3,
  selected_fill = "#9A9AFF50",
  plot_centroids = TRUE,
  centroids_color = "#000000FF",
  centroids_label = "centroid",
  subset_id = NULL,
  subset_color = "#FFFFFF00",
  subset_fill = "#F0E4167F",
  metric_id = NULL,
  break_style = "jenks",
  choropleth_palette = "YlGnBu",
  choropleth_palette_reverse = FALSE,
  choropleth_size = 0.1,
  plot_extent = NULL,
  plot_legend = TRUE,
  plot_axes = TRUE
)

Arguments

x

A segmetric object.

type

A character. Either "base", "subset", or "choropleth".

...

Ignored.

title

A character with plot title

layers

A character. One or both of "ref_sf" and "seg_sf" (works only for type = "base" and type = "subset").

background

A character with valid color used in graph's background.

ref_color, seg_color, ref_fill, seg_fill

A character with a valid hexadecimal color in rgb or rgba format. Set the border and fill colors for reference and segmentation polygons.

ref_label, seg_label, centroids_label

A character with legend labels for reference polygons, segmentation polygons, and centroids.

ref_size, seg_size

A numeric. Set symbol's size for centroids.

ref_symbol, seg_symbol

An integer. Symbol to represent polygons' centroids (see pch param in points).

selected_fill

A character with a valid hexadecimal color in rgb or rgba format. Set the fill color of selected reference or segmentation polygons depending on subset_id.

plot_centroids

A logical. Plot centroids or not.

centroids_color

A character with a valid hexadecimal color in rgb or rgba format. Set the border colors for centroids.

subset_id

A character with subset name (required for type = "subset")

subset_color, subset_fill

A character with a valid hexadecimal color in rgb or rgba format. Set the border and fill colors for subset polygons (works only with type = "subset").

metric_id

A character with metric to be plotted in choropleth maps (required for type = "choropleth")

break_style

A character with the name of a method to compute the intervals for choropleth maps. Can be one of "sd", "equal", "pretty", "quantile", "kmeans", "hclust", "bclust", "fisher", "jenks", "dpih", and "headtails" (see style parameter in classIntervals).

choropleth_palette

A character with a valid palette to be used in choropleth plots.

choropleth_palette_reverse

A logical indicating if palette should be generated in reversely.

choropleth_size

A numeric with border size used to plot polygons.

plot_extent

A sf object. Set the map extent for a plot.

plot_legend

A logical. Plot legend or not.

plot_axes

A logical. Plot coordinates axis or not.


Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

magrittr

%>%


LEM+ dataset

Description

ref_sf: a dataset containing field boundaries from Luiz Eduardo Magalhaes municipality, Brazil.

The data covers the following extent: xmin: -46.37683 ymin: -12.34579 xmax: -46.15776 ymax: -12.13663 CRS: EPSG:4326

sample_ref_sf: a subset of ref_sf dataset.

Usage

ref_sf

sample_ref_sf

Format

These datasets are objects of class sf (inherited from tbl_df, tbl, data.frame) with 2 variables:

ref_sf: a dataset with 195 features.

sample_ref_sf: a dataset with 5 features.

Source

Oldoni et al. (2020) doi: 10.1016/j.dib.2020.106553.

References

Examples

data("ref_sf", package = "segmetric")
data("sample_ref_sf", package = "segmetric")

Segmentation dataset

Description

seg200_sf,seg500_sf,seg800_sf,seg1000_sf: a dataset containing segments generated from PlanetScope image, level 3B, acquired on Feb 18, 2020, with 3.7-meter resolution (Planet Team, 2017), using the multiresolution segmentation method (Baatz and Schape, 2000).

The data covers the approximately the same area of LEM+ dataset (see ref_sf).

The data was post-processed using the spectral difference algorithm on band 3.

The polygons were simplified using the Douglas-Peucker algorithm in QGIS.

Self-intersections were removed using SAGA's Polygon Self-Intersection.

Segmentation parameters:

Spectral difference parameters:

Simplification parameter:

Only those polygons intersecting reference data with an area-perimeter ratio above 25 were selected.

sample_seg_sf: a subset of seg_sf dataset.

Usage

seg200_sf

seg500_sf

seg800_sf

seg1000_sf

sample_seg_sf

Format

These datasets are objects of class sf (inherited from tbl_df, tbl, data.frame) with 2 variables:

seg200_sf: a dataset with 547 features. seg500_sf: a dataset with 215 features. seg800_sf: a dataset with 169 features. seg1000_sf: a dataset with 158 features.

An object of class sf (inherits from tbl_df, tbl, data.frame) with 215 rows and 2 columns.

An object of class sf (inherits from tbl_df, tbl, data.frame) with 169 rows and 2 columns.

An object of class sf (inherits from tbl_df, tbl, data.frame) with 158 rows and 2 columns.

sample_seg_sf: a dataset with 6 features extracted from seg500_sf dataset.

References

Examples

data("seg200_sf", package = "segmetric")
data("seg500_sf", package = "segmetric")
data("seg800_sf", package = "segmetric")
data("seg1000_sf", package = "segmetric")
data("sample_seg_sf", package = "segmetric")

General functions

Description

These functions manipulate segmetric objects.

Usage

.segmetric_check(m)

.segmetric_env(m)

sm_read(ref_sf, seg_sf)

sm_clear(m)

## S3 method for class 'segmetric'
summary(object, weight = NULL, na_rm = TRUE, ...)

sm_is_empty(m)

## S3 method for class 'segmetric'
x[i]

Arguments

m

A segmetric object.

ref_sf

A sf object. The reference polygons.

seg_sf

A sf object. The segmentation polygons.

object

A segmetric object.

weight

Weights to summarize metrics. Accepts character options "ref", "seg", and "inter", that weights using reference, segment, and intersection areas, respectively. Also accepts a numeric vector of weights of the same length as input metrics giving the weights to be used.

na_rm

Should missing values (including NaN) be removed?

...

Additional parameters (Not implemented).

Value

See Also

sm_compute()

Examples

# load sample datasets
data("sample_ref_sf", package = "segmetric")
data("sample_seg_sf", package = "segmetric")

# create segmetric object
m <- sm_read(ref_sf = sample_ref_sf, seg_sf = sample_seg_sf)

# plot geometries
plot(m)

# compute a metric
sm_compute(m, "AFI")

# summarize the metric using mean
sm_compute(m, "AFI") %>% summary()

# clear computed subsets
sm_clear(m)


Set functions

Description

These functions compute subsets required to calculate segmentation metrics as described in Clinton et al. (2010) and Costa et al. (2017).

Usage

sm_ytilde(m)

sm_xtilde(m)

sm_yprime(m)

sm_xprime(m)

sm_ya(m)

sm_yb(m)

sm_yc(m)

sm_yd(m)

sm_ystar(m)

sm_ycd(m)

sm_ye(m)

sm_yf(m)

sm_yg(m)

Arguments

m

A segmetric object.

Value

References

Clinton, N., Holt, A., Scarborough, J., Yan, L., & Gong, P. (2010). Accuracy Assessment Measures for Object-based Image Segmentation Goodness. Photogrammetric Engineering & Remote Sensing, 76(3), 289–299. doi: 10.14358/PERS.76.3.289.

Costa, H., Foody, G. M., & Boyd, D. S. (2018). Supervised methods of image segmentation accuracy assessment in land cover mapping. Remote Sensing of Environment, 205(December 2017), 338–351. doi: 10.1016/j.rse.2017.11.024.


Subset handling functions

Description

These functions are intended to be used in new metric extensions. They handle subset_sf data (inherited from sf class) stored in segmetric objects.

Usage

sm_list(m)

sm_exists(m, subset_id)

sm_subset(m, subset_id, expr = NULL)

sm_indirect(s)

sm_segmetric(s)

sm_get(m, subset_id)

sm_ref(m)

sm_seg(m)

sm_inset(s1, s2, return_index = FALSE)

## S3 method for class 'ref_sf'
sm_inset(s1, s2, return_index = FALSE)

## S3 method for class 'seg_sf'
sm_inset(s1, s2, return_index = FALSE)

## S3 method for class 'subset_sf'
sm_inset(s1, s2, return_index = FALSE)

sm_group_by(s, by, fn, ...)

Arguments

m

A segmetric object.

subset_id

A character value informing a subset name.

expr

A valid piece of code in R inside curly braces. This code is evaluated to generate a subset.

s, s1, s2

Either a ref_sf, a seg_sf, or a subset_sf object.

return_index

A logical value indicating if the corresponding rows in s1 should be returned instead of the actual corresponding values of s2.

by

A character value with the column to group.

fn

A function to apply on each group.

...

For sm_group_by(), extra parameter to pass to fn function.

Value

Examples

# load sample datasets
data("sample_ref_sf", package = "segmetric")
data("sample_seg_sf", package = "segmetric")

# create segmetric object
m <- sm_read(ref_sf = sample_ref_sf, seg_sf = sample_seg_sf)

# lists only 'ref_sf' and 'seg_sf'
sm_list(m)

# computes 'Y_tilde' subset and stores it as 'test_subset' subset id
# sm_ytilde(m) also stores a subset under 'Y_tilde' id
s <- sm_subset(m, "test_subset", sm_ytilde(m))

# lists 'ref_sf', 'seg_sf', 'test_subset', and 'Y_tilde'
sm_list(m)

# which segmetric object stores `s` subset?
m2 <- sm_segmetric(s)

# m is identical to m2
identical(m, m2)

# which name `s` subset is stored in `m` segmetric object?
sm_indirect(s)

# retrieve 'test_subset' data from `m` object
s2 <- sm_get(m, 'test_subset')

# s is identical to s2
identical(s, s2)