A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
moments
ArrayFire Functions | ArrayFire Functions by Category » Image Processing » Image moments

## Functions
AFAPI void | moments (double *out, const array &in, const momentType moment=AF_MOMENT_FIRST_ORDER)
| C++ Interface for calculating an image moment.
AFAPI array | moments (const array &in, const momentType moment=AF_MOMENT_FIRST_ORDER)
| C++ Interface for calculating image moments.
AFAPI af_err | af_moments (af_array *out, const af_array in, const af_moment_type moment)
| C Interface for finding image moments.
AFAPI af_err | af_moments_all (double *out, const af_array in, const af_moment_type moment)
| C Interface for calculating image moment(s) of a single image.

## Detailed Description

The af::moments() function allows for finding different properties of image regions. Currently, ArrayFire calculates all first order moments. The moments are defined within the af_moment_type enum.

As the enum details, each moment can be returned individually or all first-order moments can be calculated at once. This can be done as follows:

af::array moments = af::moments(input_image, AF_MOMENT_FIRST_ORDER);
af::array
A multi dimensional data container.
Definition array.h:37
AF_MOMENT_FIRST_ORDER
@ AF_MOMENT_FIRST_ORDER
Definition defines.h:400
af::moments
AFAPI void moments(double *out, const array &in, const momentType moment=AF_MOMENT_FIRST_ORDER)
C++ Interface for calculating an image moment.

Here is an example of how the shorthand versions might be used to find the area(or gray level sum) and center of mass of an image:

double m00, m01, m10;
af::moments(&m00, input_image, AF_MOMENT_M00);
af::moments(&m01, input_image, AF_MOMENT_M01);
af::moments(&m10, input_image, AF_MOMENT_M10);
double area = m00;
double x_center = m10 / m00;
double y_center = m01 / m00;
AF_MOMENT_M10
@ AF_MOMENT_M10
Definition defines.h:398
AF_MOMENT_M01
@ AF_MOMENT_M01
Definition defines.h:397
AF_MOMENT_M00
@ AF_MOMENT_M00
Definition defines.h:396

## Function Documentation

## ◆ af_moments()

AFAPI af_err af_moments | ( | af_array * | out,
|  | const af_array | in,
|  | const af_moment_type | moment )

C Interface for finding image moments.

Parameters

  [out] | out | is an array containing the calculated moments
  [in] | in | is an array of image(s)
  [in] | moment | is moment(s) to calculate

Returns
  ref AF_SUCCESS if the moment calculation is successful, otherwise an appropriate error code is returned.

## ◆ af_moments_all()

AFAPI af_err af_moments_all | ( | double * | out,
|  | const af_array | in,
|  | const af_moment_type | moment )

C Interface for calculating image moment(s) of a single image.

Parameters

  [out] | out | is a pointer to a pre-allocated array where the calculated moment(s) will be placed. User is responsible for ensuring enough space to hold all requested moments
  [in] | in | is the input image
  [in] | moment | is moment(s) to calculate

Returns
  ref AF_SUCCESS if the moment calculation is successful, otherwise an appropriate error code is returned.

## ◆ moments() [1/2]

AFAPI array moments | ( | const array & | in,
|  | const momentType | moment = AF_MOMENT_FIRST_ORDER )

C++ Interface for calculating image moments.

Parameters

  [in] | in | contains the input image(s)
  [in] | moment | is moment(s) to calculate

Returns
  array containing the requested moment of each image

## ◆ moments() [2/2]

AFAPI void moments | ( | double * | out,
|  | const array & | in,
|  | const momentType | moment = AF_MOMENT_FIRST_ORDER )

C++ Interface for calculating an image moment.

Parameters

  [out] | out | is a pointer to a pre-allocated array where the calculated moment(s) will be placed. User is responsible for ensuring enough space to hold all requested moments
  [in] | in | is the input image
  [in] | moment | is moment(s) to calculate