# NOT RUN {
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las = readLAS(LASfile, select = "xyz", filter = "-drop_z_below 0")
# point-cloud-based method
ttops = tree_detection(las, 5)
plot(las)
with(ttops, rgl::points3d(X, Y, Z, col = "red", size = 5, add = TRUE))
# raster-based method
chm = grid_canopy(las, 1, subcircle = 0.15)
chm = as.raster(chm)
kernel = matrix(1,3,3)
chm = raster::focal(chm, w = kernel, fun = median, na.rm = TRUE)
ttops = tree_detection(chm, 5)
raster::plot(chm, col = height.colors(30))
raster::plot(ttops, add = TRUE, col = "black", legend = FALSE)
# }
Run the code above in your browser using DataLab