# NOT RUN {
LASfile <- system.file("extdata", "Tree.laz", package="lidR")
las = readLAS(LASfile, XYZonly = TRUE, filter = "-drop_z_below 0")
# compute a canopy image
chm = grid_canopy(las, res = 0.5, subcircle = 0.1, na.fill = "knnidw", k = 4)
chm = as.raster(chm)
# smoothing post-process (e.g. 2x mean)
kernel = matrix(1,3,3)
chm = raster::focal(chm, w = kernel, fun = mean)
chm = raster::focal(chm, w = kernel, fun = mean)
raster::plot(chm, col = height.colors(50)) # check the image
# segmentation
lastrees(las, "dalponte2016", chm, th = 5)
# plot points that actually are trees
trees = lasfilter(las, !is.na(treeID))
plot(trees, color = "treeID", colorPalette = random.colors(100))
# }
Run the code above in your browser using DataLab