A high-performance general-purpose compute library

The af::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 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:

A multi dimensional data container.
Definition: array.h:37
@ AF_MOMENT_FIRST_ORDER
Definition: defines.h:400
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
Definition: defines.h:398
@ AF_MOMENT_M01
Definition: defines.h:397
@ 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]outis an array containing the calculated moments
[in]inis an array of image(s)
[in]momentis 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]outis 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]inis the input image
[in]momentis 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]incontains the input image(s)
[in]momentis 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]outis 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]inis the input image
[in]momentis moment(s) to calculate