# moments_any_xld (Operator)

## Name

`moments_any_xld` — Arbitrary geometric moments of contours or polygons.

## Signature

`moments_any_xld(XLD : : Mode, PointOrder, Area, CenterRow, CenterCol, P, Q : M)`

## Description

`moments_any_xld` calculates arbitrary moments `M` of the regions enclosed by the contours or polygons `XLD`. The moments are computed by applying Green's theorem using only the points on the contour or polygon, i.e., no region is generated explicitly for the purpose of calculating the features. It is assumed that the contours or polygons are closed. If this is not the case `moments_any_xld` will artificially close the contours or polygons.

It should be noted that `moments_any_xld` only returns useful results if the contour or polygon encloses a region in the plane. In particular, the contour or polygon must not intersect itself. This is particularly important if open contours or polygons are passed because they are closed automatically, which can produce a self-intersection. To test whether the contours or polygons intersect themselves, `test_self_intersection_xld` can be used. If the contour or polygon intersects itself, useful values for the moments can be calculated with `moments_any_points_xld`.

The computed moments are normalized depending on the desired mode `Mode`:

'unnormalized':

No normalization. Let be the enclosed image region. Then the computed moment is equivalent to:

'unnormalized_central':

Shift the region by its centroid [`CenterRow`, `CenterCol`]:

'normalized':

Normalization by the area `Area` of the enclosed image region:

'central':

Normalization by the area `Area` of the enclosed image region and a shift of the region by it's centroid [`CenterRow`, `CenterCol`]:

For the normalization of the moments three specific moments are used: The area `Area` of the enclosed image region and the coordinates `CenterRow`,`CenterCol` of it's centroid (this values can be calculated with `area_center_xld`). In addition to that `moments_any_xld` expects information about the point order of the input contours/polygons in `PointOrder`, see `area_center_xld` again.

If more than one contour or polygon is passed, `M` contains all desired moments of the first contour/polygon followed by all the moments of the second contour/polygon and so forth.

## Execution Information

• Multithreading type: reentrant (runs in parallel with non-exclusive operators).
• Processed without parallelization.

## Parameters

`XLD` (input_object)  xld(-array) `→` object

Contours or polygons to be examined.

`Mode` (input_control)  string `→` (string)

Computation mode.

Default: 'unnormalized'

Suggested values: 'unnormalized', 'unnormalized_central', 'normalized', 'central'

`PointOrder` (input_control)  string(-array) `→` (string)

Point order along the boundary.

Default: 'positive'

Suggested values: 'positive', 'negative'

`Area` (input_control)  real(-array) `→` (real)

Area enclosed by the contour or polygon.

`CenterRow` (input_control)  point.y(-array) `→` (real)

Row coordinate of the centroid.

`CenterCol` (input_control)  point.x(-array) `→` (real)

Column coordinate of the centroid.

`P` (input_control)  point.x(-array) `→` (integer)

First index of the desired moments .

Default: 1

Suggested values: 0, 1, 2, 3, 4

`Q` (input_control)  point.x(-array) `→` (integer)

Second index of the desired moments .

Default: 1

Suggested values: 0, 1, 2, 3, 4

`M` (output_control)  real(-array) `→` (real)

The computed moments.

## Complexity

Let n be the number of points of the contour or polygon. Then the run time is O(n).

## Result

`moments_any_xld` returns 2 ( H_MSG_TRUE) if the input is not empty. If the input is empty the behavior can be set via `set_system(::'no_object_result',<Result>:)`. If necessary, an exception is raised.

## Possible Predecessors

`area_center_xld`, `gen_contours_skeleton_xld`, `smooth_contours_xld`, `gen_polygons_xld`

## Alternatives

`moments_xld`, `moments_any_points_xld`

`moments_xld`, `area_center_xld`, `moments_region_2nd`, `area_center`