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)
# maxima selection
selected_maxi <- maxima_selection(maxi, chm_chablais3, dm = 1, dprop = 0.1)
# segmentation
seg_maxi <- segmentation(maxi, chm_chablais3)
seg_selected_maxi <- segmentation(selected_maxi, chm_chablais3)
# plot original image
terra::plot(chm_chablais3, main = "Median filter")
# plot segmented image
# replace segment with id 0 (not a tree) with NA
seg_maxi[seg_maxi == 0] <- NA
terra::plot(seg_maxi %% 8, main = "Segments, no maxima selection",
col = rainbow(8))
seg_selected_maxi [seg_selected_maxi == 0] <- NA
terra::plot(seg_selected_maxi %% 8, main = "Segments, maxima selection",
col = rainbow(8))
Run the code above in your browser using DataLab