Skip to contents

The function segments a mosaic using an interative process where the user picks samples from background (eg., soil) and foreground (eg., plants).

Usage

mosaic_segment_pick(
  mosaic,
  basemap = NULL,
  g = 2,
  r = 3,
  b = 1,
  max_pixels = 2e+06,
  downsample = NULL,
  quantiles = c(0, 1),
  return = c("mosaic", "mask")
)

Arguments

mosaic

A mosaic of class SpatRaster, generally imported with mosaic_input().

basemap

An optional mapview object.

r, g, b

The layer for the Red, Green and Blue band, respectively. Defaults to 1, 2, and 3.

max_pixels

Maximum number of pixels to render in the map or plot (default: 500000).

downsample

Downsampling factor to reduce the number of pixels (default: NULL). In this case, if the number of pixels in the image (width x height) is greater than max_pixels a downsampling factor will be automatically chosen so that the number of plotted pixels approximates the max_pixels.

quantiles

the upper and lower quantiles used for color stretching.

return

The output of the function. Either 'mosaic' (the segmented mosaic), or 'mask' (the binary mask).

Value

An SpatRaster object with the segmented mosaic (if return = 'mosaic') or a mask (if return = 'mask').

Examples

if (interactive() && requireNamespace("EBImage")) {
 mosaic <- mosaic_input(system.file("ex/elev.tif", package="terra"))
 seg <- mosaic_segment_pick(mosaic)
 mosaic_plot(seg)
}
#> Warning: The current raster is in the lat/lon coordinate system, which may result in processing errors when trying to segment individuals in the `mosaic_analyze()` function. It is highly suggested to reproject the raster using mosaic_project() with EPSG:32632
#> class       : SpatRaster 
#> dimensions  : 90, 95, 1  (nrow, ncol, nlyr)
#> resolution  : 0.008333333, 0.008333333  (x, y)
#> extent      : 5.741667, 6.533333, 49.44167, 50.19167  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326) 
#> source      : elev.tif 
#> name        : elevation 
#> min value   :       141 
#> max value   :       547 
#> 
#> Listening on http://127.0.0.1:6534
#> Error in UseMethod("st_transform"): no applicable method for 'st_transform' applied to an object of class "NULL"