WatershedAlgorithm¶
WatershedAlgorithm divides a raster into basins, flooding it from its minima as water filling a landscape. Turned upside down, a canopy height model floods from the tops of the trees, and each basin is then a crown: its area and shape, around the tops found by RasterMaximaFinder. The output is the number of the basin of each cell, or the lines between the basins.
Details¶
The raster is seen as a surface that is flooded from its minima: the water rises level by level, each minimum fills its own basin, and where the waters of two basins meet the cells become watershed lines. The algorithm is the immersion of Vincent and Soille (1991), from the ImageJ plugin of Christopher Mei.
The algorithm works on 256 levels: the valid values are stretched linearly from their minimum to their maximum on the levels 0 to 254, so that on a canopy height model of 40 m a level is about 16 cm. Cells closer than a level are flat for the algorithm. The cells with no value are left out, they are no basin and no line.
Inverted, the levels are turned upside down and the flood starts from the maxima: on a canopy height model each basin is then the crown around a top. Every small bump of the surface is a top of its own and makes a basin, so that a raw canopy model, noisy from cell to cell, is split in many small pieces: smoothed, as with a gaussian KernelDensity of a couple of cells, it gives fewer crowns, closer to the trees. The ground and the low vegetation make basins too: setting them to no value first, as with Mapcalc, leaves them out.
Where the waters of different basins meet on a flat area, the whole area can become watershed line, not only a line one cell wide.
With the borders, the cells of the watershed lines next to a basin have the value 1. Without, each cell has the number of its basin, from 1, and the watershed lines have no value.
Parameters¶
Divides a raster into the basins of its minima, or of its maxima if inverted, as the crowns of the trees of a canopy height model, with the immersion algorithm of Vincent and Soille (1991).
Toolbox folder: Lesto › vegetation
Status: Experimental
Keywords: watershed, segmentation, crowns, lidar
Authors: Christopher Mei, Lee Vincent and Pierre Soille 1991, Andrea Antonello (hm port)
Class: org.hortonmachine.lesto.modules.vegetation.WatershedAlgorithm
Inputs
Parameter |
Type |
Unit |
Default |
Description |
|---|---|---|---|---|
|
raster file |
The raster to divide, as a canopy height model. |
||
|
boolean |
|
If true, the raster is flooded upside down, from its maxima: the basins are then the crowns around the tops of a canopy height model. |
|
|
boolean |
|
If true, the output has 1 on the watershed lines between the basins, else the number of the basin of each cell. |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
output file |
The watershed lines or the basins. |
References
Vincent, L., Soille, P. (1991). Watersheds in digital spaces: an efficient algorithm based on immersion simulations. IEEE Transactions on Pattern Analysis and Machine Intelligence, 13(6), 583-598.
Example¶
The crowns of the canopy height model of Las2RasterInterpolator: first without the ground and the low vegetation, set to no value with Mapcalc, then smoothed with KernelDensity, so that the small bumps of the canopy do not make crowns of their own:
import org.hortonmachine.lesto.modules.vegetation.WatershedAlgorithm
import org.hortonmachine.modules.KernelDensity
import org.hortonmachine.modules.Mapcalc
// the folder with the lidar survey: change it to yours
var folder = "/data/flanginec/"
// the canopy height model of Las2RasterInterpolator without the ground and the
// low vegetation, under 2 m, that would make basins of their own
var mapcalc = new Mapcalc()
mapcalc.inRaster1 = folder + "chm_idw.tif"
mapcalc.pFunction = """
images {
chm_idw = read;
chm_trees = write;
}
chm_trees = chm_idw < 2 ? null : chm_idw;
"""
mapcalc.outRaster = folder + "chm_trees.tif"
mapcalc.process()
// smoothed with a gaussian kernel of 2 cells, so that the small bumps of the
// canopy do not make crowns of their own: only the order of the values counts
var kernel = new KernelDensity()
kernel.inMap = folder + "chm_trees.tif"
kernel.pKernel = 4
kernel.pRadius = 2
kernel.outDensity = folder + "chm_smooth.tif"
kernel.process()
// the crowns of the trees: the canopy flooded upside down, from its tops
var watershed = new WatershedAlgorithm()
watershed.inRaster = folder + "chm_smooth.tif"
watershed.doInvert = true
watershed.doBorders = false
watershed.outRaster = folder + "crowns.tif"
watershed.process()
The 107 crowns, each in its own color, over the hillshade of the elevation model: round patches of a few meters where the trees are, divided by thin lines without value, and the open ground left out.¶
On the canopy model as it is, noisy from cell to cell, the same flood gives more than 400 small pieces.