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")
Run the code above in your browser using DataLab