raster_zonal_stats {lidaRtRee}R Documentation

Image statistic in segment

Description

compute zonal statistic of an image

Usage

raster_zonal_stats(segms, dem_nl, fun = max)

Arguments

segms

cimg or SpatRaster object. image with segments id (e.g. from segmentation)

dem_nl

cimg or SpatRaster object. image to compute statistic from

fun

function to compute statistics from values in each segment

Value

A cimg object or raster object with values of the statistic

See Also

segmentation

Examples

data(chm_chablais3)
chm_chablais3 <- terra::rast(chm_chablais3)

# median filter
chm_chablais3 <- dem_filtering(chm_chablais3,
  nl_filter = "Median", nl_size = 3,
  sigma = 0
)$non_linear_image

# maxima detection
maxi <- maxima_detection(chm_chablais3)

# segmentation
seg_maxi <- segmentation(maxi, chm_chablais3)

# compute image of maximum value in each segment
max_in_segment <- raster_zonal_stats(seg_maxi, chm_chablais3)

# plot original image
terra::plot(chm_chablais3, main = "Median filter")

# plot segments and image of max value inside segments
seg_maxi[seg_maxi == 0] <- NA
terra::plot(seg_maxi %% 8, main = "Segments", col = rainbow(8))
terra::plot(max_in_segment, main = "Max value in segment")

[Package lidaRtRee version 4.0.5 Index]