The C++ interface for areas. More...

array areas (const array &regions)
 

Detailed Description

The C++ interface for areas.

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

Function Documentation

array af::areas ( const array &  regions)
Parameters
[in]regionsnumbered connected components (see regions)
Returns
Nx2 matrix of the N components and their areas (single precision)
Note
requires a device with compute capability 1.2+