Image.moments#

Image.moments(binary: bool = False) dict[str, float][source]#

Image moments

Parameters:

binary (bool) – if True, all non-zero pixels are treated as 1’s

Returns:

image moments

Type:

dict

Compute multiple moments of the image and return them as a dict

Moment type

dict keys

moments

m00 m10 m01 m20 m11 m02 m30 m21 m12 m03

central moments

mu20 mu11 mu02 mu30 mu21 mu12 mu03 |

normalized central moments

nu20 nu11 nu02 nu30 nu21 nu12 nu03 |

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('shark1.png')
>>> img.moments()
{'m00': 1995885.0, 'm10': 341888955.0, 'm01': 309659505.0, 'm20': 60967635585.0, 'm11': 52708208790.0, 'm02': 48962122365.0, 'm30': 11284951722945.0, 'm21': 9337817849640.0, 'm12': 8282294696220.0, 'm03': 7879402188375.0, 'mu20': 2403110298.7274823, 'mu11': -335510948.49559176, 'mu02': 918768646.3012627, 'mu30': 18092682198.756256, 'mu21': -6304121879.925781, 'mu12': -657749179.171875, 'mu03': -2112760503.1506472, 'nu20': 0.0006032574252131944, 'nu11': -8.422396218245323e-05, 'nu02': 0.00023064026991512026, 'nu30': 3.2148755752296547e-06, 'nu21': -1.1201748437518821e-06, 'nu12': -1.1687497450722798e-07, 'nu03': -3.7541488118084844e-07}

Note

  • Converts a color image to greyscale.

References:

Important

Uses OpenCV function cv2.moments which accepts single-channel, CV_8U, CV_16U, CV_16S, CV_32F or CV_64F images (color images are automatically converted to greyscale).

Seealso:

mpq npq upq opencv.moments