Skip to content

moments_any_xldmoments_any_xldMomentsAnyXldMomentsAnyXldmoments_any_xldmoments_any_xld🔗

Short description🔗

moments_any_xldmoments_any_xldMomentsAnyXldMomentsAnyXldmoments_any_xldmoments_any_xld — Arbitrary geometric moments of contours or polygons.

Signature🔗

moments_any_xld( xld XLD, string Mode, string PointOrder, real Area, point.y CenterRow, point.x CenterCol, point.x P, point.x Q, out real M )moments_any_xld( XLD : : Mode, PointOrder, Area, CenterRow, CenterCol, P, Q : M )void MomentsAnyXld( const HObject& XLD, const HTuple& Mode, const HTuple& PointOrder, const HTuple& Area, const HTuple& CenterRow, const HTuple& CenterCol, const HTuple& P, const HTuple& Q, HTuple* M )static void HOperatorSet.MomentsAnyXld( HObject XLD, HTuple mode, HTuple pointOrder, HTuple area, HTuple centerRow, HTuple centerCol, HTuple p, HTuple q, out HTuple m )def moments_any_xld( xld: HObject, mode: str, point_order: MaybeSequence[str], area: MaybeSequence[float], center_row: MaybeSequence[float], center_col: MaybeSequence[float], p: MaybeSequence[int], q: MaybeSequence[int] ) -> Sequence[float]

def moments_any_xld_s( xld: HObject, mode: str, point_order: MaybeSequence[str], area: MaybeSequence[float], center_row: MaybeSequence[float], center_col: MaybeSequence[float], p: MaybeSequence[int], q: MaybeSequence[int] ) -> floatHerror moments_any_xld( const Hobject XLD, const char* Mode, const char* PointOrder, double Area, double CenterRow, double CenterCol, const Hlong P, const Hlong Q, double* M )

Herror T_moments_any_xld( const Hobject XLD, const Htuple Mode, const Htuple PointOrder, const Htuple Area, const Htuple CenterRow, const Htuple CenterCol, const Htuple P, const Htuple Q, Htuple* M )

HTuple HXLD::MomentsAnyXld( const HString& Mode, const HTuple& PointOrder, const HTuple& Area, const HTuple& CenterRow, const HTuple& CenterCol, const HTuple& P, const HTuple& Q ) const

double HXLD::MomentsAnyXld( const HString& Mode, const HString& PointOrder, double Area, double CenterRow, double CenterCol, Hlong P, Hlong Q ) const

double HXLD::MomentsAnyXld( const char* Mode, const char* PointOrder, double Area, double CenterRow, double CenterCol, Hlong P, Hlong Q ) const

double HXLD::MomentsAnyXld( const wchar_t* Mode, const wchar_t* PointOrder, double Area, double CenterRow, double CenterCol, Hlong P, Hlong Q ) const (Windows only)

HTuple HXLD.MomentsAnyXld( string mode, HTuple pointOrder, HTuple area, HTuple centerRow, HTuple centerCol, HTuple p, HTuple q )

double HXLD.MomentsAnyXld( string mode, string pointOrder, double area, double centerRow, double centerCol, int p, int q )

Description🔗

moments_any_xldMomentsAnyXld calculates arbitrary moments Mmm of the regions enclosed by the contours or polygons XLDXLDxld. 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_xldMomentsAnyXld will artificially close the contours or polygons.

It should be noted that moments_any_xldMomentsAnyXld 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_xldTestSelfIntersectionXld can be used. If the contour or polygon intersects itself, useful values for the moments can be calculated with moments_any_points_xldMomentsAnyPointsXld.

The computed moments are normalized depending on the desired mode Modemodemode:

  • ‘unnormalized’: No normalization. Let \(R\) be the enclosed image region. Then the computed moment \(M_{p,q}\) is equivalent to:

    \[\begin{eqnarray*} M_{p,q} = \int\limits_{R} r^p c^q \, dr \,dc \end{eqnarray*}\]
  • ‘unnormalized_central’: Shift the region by its centroid \([\bar{r},\bar{c}] =\) [CenterRowcenterRowcenter_row, CenterColcenterColcenter_col]:

    \[\begin{eqnarray*} M_{p,q} = \int\limits_{R} (r - \bar{r})^p (c - \bar{c})^q \, dr \,dc \end{eqnarray*}\]
  • ‘normalized’: Normalization by the area \(A =\) Areaareaarea of the enclosed image region:

    \[\begin{eqnarray*} M_{p,q} = \frac{1}{A} \int\limits_{R} r^p c^q \, dr \,dc \end{eqnarray*}\]
  • ‘central’: Normalization by the area \(A =\) Areaareaarea of the enclosed image region and a shift of the region by it’s centroid \([\bar{r},\bar{c}] =\) [CenterRowcenterRowcenter_row, CenterColcenterColcenter_col]:

    \[\begin{eqnarray*} M_{p,q} = \frac{1}{A} \int\limits_{R} (r - \bar{r})^p (c - \bar{c})^q \, dr \,dc \end{eqnarray*}\]

For the normalization of the moments three specific moments are used: The area Areaareaarea of the enclosed image region and the coordinates CenterRowcenterRowcenter_row,CenterColcenterColcenter_col of it’s centroid (this values can be calculated with area_center_xldAreaCenterXld). In addition to that moments_any_xldMomentsAnyXld expects information about the point order of the input contours/polygons in PointOrderpointOrderpoint_order, see area_center_xldAreaCenterXld again.

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

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

XLDXLDxld (input_object) xld(-array) → objectobjectHObjectHXLDHObjectHobject

Contours or polygons to be examined.

Modemodemode (input_control) string → (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Computation mode.

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

PointOrderpointOrderpoint_order (input_control) string(-array) → (string)(string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Point order along the boundary.

Default: 'positive'"positive"
Suggested values: 'positive', 'negative'"positive", "negative"

Areaareaarea (input_control) real(-array) → (real)(real)HTuple (double)HTuple (double)MaybeSequence[float]Htuple (double)

Area enclosed by the contour or polygon.

CenterRowcenterRowcenter_row (input_control) point.y(-array) → (real)(real)HTuple (double)HTuple (double)MaybeSequence[float]Htuple (double)

Row coordinate of the centroid.

CenterColcenterColcenter_col (input_control) point.x(-array) → (real)(real)HTuple (double)HTuple (double)MaybeSequence[float]Htuple (double)

Column coordinate of the centroid.

Ppp (input_control) point.x(-array) → (integer)(integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

First index of the desired moments \(M_{p,q}\).

Default: 11
Suggested values: 0, 1, 2, 3, 40, 1, 2, 3, 4

Qqq (input_control) point.x(-array) → (integer)(integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

Second index of the desired moments \(M_{p,q}\).

Default: 11
Suggested values: 0, 1, 2, 3, 40, 1, 2, 3, 4

Mmm (output_control) real(-array) → (real)(real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

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_xldMomentsAnyXld 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.

Combinations with other operators🔗

Combinations

Possible predecessors

area_center_xldAreaCenterXld, gen_contours_skeleton_xldGenContoursSkeletonXld, smooth_contours_xldSmoothContoursXld, gen_polygons_xldGenPolygonsXld

Alternatives

moments_xldMomentsXld, moments_any_points_xldMomentsAnyPointsXld

See also

moments_xldMomentsXld, area_center_xldAreaCenterXld, moments_region_2ndMomentsRegion2nd, area_centerAreaCenter

Module🔗

Foundation