regions

Functions
regions
Complete List of ArrayFire Functions ArrayFire Functions by Category » Image Processing » | Connected Components & Labeling

Find blobs in given image. More...

## Functions
AFAPI array | regions (const array &in, const af::connectivity connectivity=AF_CONNECTIVITY_4, const dtype type=f32)
| C++ Interface for getting regions in an image. More...
AFAPI af_err | af_regions (af_array *out, const af_array in, const af_connectivity connectivity, const af_dtype ty)
| C Interface for regions in an image. More...

## Detailed Description

Find blobs in given image.

Given a binary image (with zero representing background pixels), regions computes a floating point image where each connected component is labeled from 1 to N, the total number of components in the image.

A component is defined as one or more nonzero pixels that are connected by the specified connectivity (either 4-way(AF_CONNECTIVITY_4) or 8-way(AF_CONNECTIVITY_8)) in two dimensions.

An example input and output for 8-connectivity

The default connectivity is AF_CONNECTIVITY_4.

## Function Documentation

## ◆ af_regions()

AFAPI af_err af_regions | ( | af_array * | out,
|  | const af_array | in,
|  | const af_connectivity | connectivity,
|  | const af_dtype | ty
| ) |  |

C Interface for regions in an image.

Parameters

  [out] | out | array will have labels indicating different regions
  [in] | in | array should be binary image of type b8
  [in] | connectivity | can take one of the following [AF_CONNECTIVITY_4 | AF_CONNECTIVITY_8]
  [in] | ty | is type of output array

Returns
  AF_SUCCESS if the regions are identified successfully, otherwise an appropriate error code is returned.

## ◆ regions()

AFAPI array af::regions | ( | const array & | in,
|  | const af::connectivity | connectivity = `AF_CONNECTIVITY_4`,
|  | const dtype | type = `f32`
| ) |  |

C++ Interface for getting regions in an image.

Below given are sample input and output for each type of connectivity value for `type`

Example for `type` == AF_CONNECTIVITY_8 | Example for `type` == AF_CONNECTIVITY_4
af::array in(8, 8, input); //af_print(in); // in = // 0 0 0 0 1 0 1 0 // 0 0 0 0 0 0 1 1 // 0 1 0 1 0 0 0 0 // 0 0 1 0 1 1 0 1 // 1 1 0 0 0 1 0 1 // 0 0 0 1 0 0 0 1 // 0 0 0 0 1 0 0 1 // 0 1 0 0 0 1 0 0 // Compute the label matrix using 8-way connectivity af::array out = regions(in.as(b8), AF_CONNECTIVITY_8); //af_print(out); // 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 | af::array in(8, 8, input); //af_print(in.T()); //in //0 0 0 0 1 0 1 0 //0 0 0 0 0 0 1 1 //0 1 0 1 0 0 0 0 //0 0 1 0 1 1 0 1 //1 1 0 0 0 1 0 1 //0 0 0 1 0 0 0 1 //0 0 0 0 1 0 0 1 //0 1 0 0 0 1 0 0 // Compute the label matrix using 4-way connectivity af::array out = regions(in.as(b8), AF_CONNECTIVITY_4); //af_print(out.T()); //out //0 0 0 0 7 0 11 0 //0 0 0 0 0 0 11 11 //0 2 0 5 0 0 0 0 //0 0 4 0 8 8 0 12 //1 1 0 0 0 8 0 12 //0 0 0 6 0 0 0 12 //0 0 0 0 9 0 0 12 //0 3 0 0 0 10 0 0

Parameters

  [in] | in | array should be binary image of type b8
  [in] | connectivity | can take one of the following [AF_CONNECTIVITY_4 | AF_CONNECTIVITY_8]
  [in] | type | is type of output array

Returns
  returns array with labels indicating different regions. Throws exceptions if any issue occur.