moments

Functions
moments
Complete List of ArrayFire Functions ArrayFire Functions by Category » Image Processing » | Image moments

The moments() function allows for finding different properties of image regions. More...

## Functions
AFAPI void | moments (double *out, const array &in, const momentType moment=AF_MOMENT_FIRST_ORDER)
| C++ Interface for calculating an image moment. More...
AFAPI array | moments (const array &in, const momentType moment=AF_MOMENT_FIRST_ORDER)
| C++ Interface for calculating image moments. More...
AFAPI af_err | af_moments (af_array *out, const af_array in, const af_moment_type moment)
| C Interface for finding image moments. More...
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. More...

## Detailed Description

The 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);

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;

## 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 void af::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

## ◆ moments() [2/2]

AFAPI array af::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