seg_adjust {lidaRtRee}R Documentation

Modification of segments based on values

Description

in a segmented image, removes from segments the pixels which values in a reference image is below a certain percentage of the highest value inside the segment. Removed pixels are attributed 0 value.

Usage

seg_adjust(dem_w, dem_wh, dem_nl, prop = 0.3, min.value = 2, min.maxvalue = 5)

Arguments

dem_w

cimg or SpatRaster object. image with segments id, without 0 values

dem_wh

cimg or SpatRaster object. image with max value inside segment

dem_nl

cimg or SpatRaster object. image with initial values

prop

numeric. proportional threshold for removal of pixels which initial values are lower than the max height of the segment (dem_nl < prop x dem_wh)

min.value

numeric. threshold for removel of pixels which initial values are lower (dem_nl < min.value)

min.maxvalue

numeric. threshold for complete removal of segments which maximum value height is smaller to the threshold (dem_wh < min.maxvalue)

Value

A cimg or SpatRaster object: image with modified segments.

See Also

maxima_detection, maxima_selection

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 and selection
maxi <- maxima_detection(chm_chablais3)
selected_maxi <- maxima_selection(maxi, chm_chablais3, dm = 1, dprop = 0.1)

# segmentation
seg_selected_maxi <- segmentation(selected_maxi, chm_chablais3)

# max value in segments
max_in_segment <- raster_zonal_stats(seg_selected_maxi , chm_chablais3)

# segmentation modification
seg_modif1 <- seg_adjust(seg_selected_maxi , max_in_segment,
  chm_chablais3,
  prop = 0.5
)
seg_modif2 <- seg_adjust(seg_selected_maxi , max_in_segment,
  chm_chablais3,
  prop = 0, min.value = 5, min.maxvalue = 10
)

# plot initial segmented image
# seg_selected_maxi[seg_selected_maxi == 0] <- NA
terra::plot(seg_selected_maxi %% 8, main = "Initial segments", col = rainbow(8))
# seg_modif1[seg_modif1 == 0] <- NA
terra::plot(seg_modif1 %% 8, main = "Modified segments 1", col = rainbow(8))
seg_modif2[seg_modif2 == 0] <- NA
terra::plot(seg_modif2 %% 8, main = "Modified segments 2", col = rainbow(8))

[Package lidaRtRee version 4.0.5 Index]