当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python skimage.measure.moments_coords_central用法及代码示例


用法:

skimage.measure.moments_coords_central(coords, center=None, order=3)

计算达到特定顺序的所有中心图像时刻。

可以从原始图像时刻计算以下属性:
  • 区域为:M[0, 0]
  • 质心为:{ M[1, 0] / M[0, 0] , M[0, 1] / M[0, 0] }。

请注意,原始矩既不是平移、缩放也不是旋转不变的。

参数

coords(N, D) 双精度或 uint8 数组

说明笛卡尔空间中 D 维图像的 N 点数组。 np.nonzero 返回的坐标元组也被接受为输入。

center浮点数元组,可选

图像质心的坐标。如果未提供,则会计算此值。

orderint 可选

时刻的最大顺序。默认值为 3。

返回

Mc(order + 1order + 1,...)数组

中心图像时刻。 (D 尺寸)

参考

1

Johannes Kilian. Simple Image Analysis By Moments. Durham University, version 0.2, Durham, 2001.

例子

>>> coords = np.array([[row, col]
...                    for row in range(13, 17)
...                    for col in range(14, 18)])
>>> moments_coords_central(coords)
array([[16.,  0., 20.,  0.],
       [ 0.,  0.,  0.,  0.],
       [20.,  0., 25.,  0.],
       [ 0.,  0.,  0.,  0.]])

如上所示,对于对称对象,odd-order 矩(第 1 和第 3 列,第 1 和第 3 行)以对象的质心或质心为中心时为零(默认值)。如果我们通过添加一个新点来打破对称性,则不再成立:

>>> coords2 = np.concatenate((coords, [[17, 17]]), axis=0)
>>> np.round(moments_coords_central(coords2),
...          decimals=2)  
array([[17.  ,  0.  , 22.12, -2.49],
       [ 0.  ,  3.53,  1.73,  7.4 ],
       [25.88,  6.02, 36.63,  8.83],
       [ 4.15, 19.17, 14.8 , 39.6 ]])

当中心为 (0, 0) 时,图像矩和中心图像矩是等价的(根据定义):

>>> np.allclose(moments_coords(coords),
...             moments_coords_central(coords, (0, 0)))
True

相关用法


注:本文由纯净天空筛选整理自scikit-image.org大神的英文原创作品 skimage.measure.moments_coords_central。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。