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
m00m10m01m20m11m02m30m21m12m03central moments
mu20mu11mu02mu30mu21mu12mu03|normalized central moments
nu20nu11nu02nu30nu21nu12nu03|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:
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 12.1.3.4.
Important
Uses OpenCV function
cv2.momentswhich accepts single-channel, CV_8U, CV_16U, CV_16S, CV_32F or CV_64F images (color images are automatically converted to greyscale).- Seealso: