Labeler

Gives a number to every group of valid cells that touch each other, the connected components of the raster, also called patches or regions. The value of the cells doesn’t matter, only if they are valid or novalue: a raster of classes is first cut to the class of interest, for example with the inverse switch of RasterNull.

The labels turn a mask into separate objects, as the single landslides, lakes or tree crowns of a map, that can then be counted, measured with RasterSummary or vectorized.

Details

The cells are connected also by the corners, as in the 8 directions of the flow: a diagonal line of cells is a single component. The value of the cells doesn’t matter, only if they are valid or novalue, so a raster of classes has to be cut to a class first, for example with RasterNull and its inverse switch. The components are numbered from 1, in the order in which their first cell is met reading the raster from the north-west corner by rows; the novalue cells stay novalue.

The labels give an identifier to every patch of a mask, as the single tree crowns, the landslides or the lakes of a map, to count them, to measure their area with RasterSummary or to vectorize them.

Parameters

Labels the connected components of a raster: every group of valid cells that touch each other gets its own number.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Labeling, Connected components, Patches, Raster
Authors: Andrea Antonello
Class: org.hortonmachine.modules.Labeler

Inputs

Parameter

Type

Unit

Default

Description

inMap

raster file

The raster to label: its valid cells are the ones to group.

Outputs

Parameter

Type

Unit

Description

outMap

output file

The raster of the labels, the number of the component of each valid cell.

Example

The example runs on the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, each module on the outputs of the previous ones. It labels the patches of the middle elevation belt cut by RasterNull:

import org.hortonmachine.modules.Labeler

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

// the middle elevation belt of the RasterNull example, split by the valleys and the ridges:
// every separate patch of it gets its own number
var labeler = new Labeler()
labeler.inMap = folder + "belt_middle.tif"
labeler.outMap = folder + "belt_middle_patches.tif"
labeler.process()
The separate patches of the middle elevation belt, each with its own number and color.

The separate patches of the middle elevation belt, each with its own number and color.