Learn R Programming

lidR (version 2.1.4)

watershed: Individual Tree Segmentation Algorithm

Description

This function is made to be used in lastrees. It implements an algorithm for tree segmentation based on a watershed or a marker-controlled watershed.

  • Simple watershed is based on the bioconductor package EBIimage. You need to install this package to run this method (see its github page). Internally, the function EBImage::watershed is called.

  • Marker-controlled watershed is based on the imager package. Internally, the function imager::watershed is called using the tree tops as a priority map.

Usage

watershed(chm, th_tree = 2, tol = 1, ext = 1)

mcwatershed(chm, treetops, th_tree = 2, ID = "treeID")

Arguments

chm

RasterLayer. Image of the canopy. Can be computed with grid_canopy or read from an external file.

th_tree

numeric. Threshold below which a pixel cannot be a tree. Default is 2.

tol

numeric. Tolerance see ?EBImage::watershed.

ext

numeric. see ?EBImage::watershed.

treetops

SpatialPointsDataFrame. Can be computed with tree_detection or read from an external shapefile.

ID

character. If the SpatialPointsDataFrame contains an attribute with the ID for each tree, the name of this column. This way, original IDs will be preserved. If there is no such data trees will be numbered sequentially.

Details

Because this algorithm works on a CHM only there is no actual need for a point cloud. Sometimes the user does not even have the point cloud that generated the CHM. lidR is a point cloud-oriented library, which is why this algorithm must be used in lastrees to merge the result into the point cloud. However, the user can use this as a stand-alone function like this:

 chm = raster("file/to/a/chm/")
 ttops = tree_detection(chm, lmf(3))
 crowns = watershed(chm)()

See Also

Other individual tree segmentation algorithms: dalponte2016, li2012, silva2016

Other raster based tree segmentation algorithms: dalponte2016, silva2016

Examples

Run this code
# NOT RUN {
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile, select = "xyz", filter = "-drop_z_below 0")
col <- pastel.colors(250)

chm <- grid_canopy(las, res = 0.5, p2r(0.3))
ker <- matrix(1,3,3)
chm <- raster::focal(chm, w = ker, fun = mean, na.rm = TRUE)

ttops <- tree_detection(chm, lmf(4, 2))
las   <- lastrees(las, mcwatershed(chm, ttops))

x = plot(las, color = "treeID", colorPalette = col)
add_treetops3d(x, ttops)
# }

Run the code above in your browser using DataLab