Calculate the area of each numbered component in a label matrix. More...

Modules

 areas
 The C++ interface for areas.
 

Detailed Description

Calculate the area of each numbered component in a label matrix.

Count the number of pixels (or area) of each connected component in a label matrix. This matrix should be 2D, single precision floating point data where zero represents background pixels and the components are numbered sequentially from 1 to N, where N is the overall number of components.

// Get a label matrix for the connected components in an image
const int len = 8;
array r = randn(len, len) * 10.0f;
// Convert to binary
array in = (r > 5.0f);
array labels = regions(in);
print(labels);
// 0 0 0 0 4 0 5 0
// 0 0 0 0 0 0 5 5
// 0 1 0 1 0 0 0 0
// 0 0 1 0 1 1 0 6
// 1 1 0 0 0 1 0 6
// 0 0 0 3 0 0 0 6
// 0 0 0 0 3 0 0 6
// 0 2 0 0 0 3 0 0
array a = areas(labels);
print(a);
// 1 8
// 2 1
// 3 3
// 4 1
// 5 3
// 6 4