data(chm_chablais3)
chm_chablais3 <- terra::rast(chm_chablais3)
# fill NA values in canopy height model
chm_chablais3[is.na(chm_chablais3)] <- 0
# gap detection with distance larger than canopy height / 2
gaps <- gap_detection(chm_chablais3, ratio = 2, gap_max_height = 1,
min_gap_surface = 0)
# gap detection with distance larger than canopy height / 2
# and reconstruction of border areas
gaps1 <- gap_detection(chm_chablais3,
ratio = 2, gap_max_height = 1, min_gap_surface = 0,
gap_reconstruct = TRUE
)
# gap detection without distance criterion
gaps2 <- gap_detection(chm_chablais3, ratio = NULL, gap_max_height = 1,
min_gap_surface = 0)
# gap id and corresponding surface for third detection parameters
table(terra::values(gaps2$gap_id)) * terra::res(gaps2$gap_id)[1]^2
# plot original image
terra::plot(chm_chablais3, main = "Initial image")
# plot binary image of gaps
terra::plot(gaps$gap_id > 0, main = "Gaps", col = "green", legend = FALSE)
terra::plot(gaps1$gap_id > 0, main = "Gaps, with reconstruction", col = "green", legend = FALSE)
terra::plot(gaps2$gap_id > 0, main = "Gaps, no width criterion", col = "green", legend = FALSE)
# plot filtered CHM
terra::plot(gaps2$filled_chm, main = "Filtered CHM")
Run the code above in your browser using DataLab