Learn R Programming

lidR (version 1.6.1)

tree_detection: Tree top detection based on local maxima filters

Description

Tree top detection based on local maxima filters. There are two types of filter. The first, called for gridded objects, works on images with a matrix-based algorithm and the second one, called for point clouds, works at the point cloud level without any rasterization.

Usage

tree_detection(x, ws, hmin = 2)

Arguments

x

A object of class LAS or an object representing a canopy height model such as a RasterLayer or a lasmetrics or a matrix.

ws

numeric. Size of the moving window used to the detect the local maxima. On a raster-like object this size is in pixels and should be an odd number larger than 3. On a raw point cloud this size is in the point cloud units (usually meters).

hmin

numeric. Minimum height of a tree. Threshold below which a pixel or a point cannot be a local maxima. Default 2.

Value

A data.table with the coordinates of the tree tops (X, Y, Z) if the input is a point cloud, or a RasterLayer if the input is a raster-like object.

Examples

Run this code
# 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