當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cucim.skimage.measure.moments_coords_central用法及代碼示例

用法:

cucim.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 點數組。 cp.nonzero 返回的坐標元組也被接受為輸入。

center浮點數元組,可選

圖像質心的坐標。如果未提供,則會計算此值。

order整數,可選

時刻的最大順序。默認值為 3。

返回

Mc(order + 1 , order + 1, …) 數組

中心圖像時刻。 (D 尺寸)

參考

1

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

例子

>>> import cupy as cp
>>> from cucim.skimage.measure import moments_coords_central
>>> coords = cp.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 = cp.concatenate((coords, [[17, 17]]), axis=0)
>>> cp.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) 時,圖像矩和中心圖像矩是等價的(根據定義):

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

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cucim.skimage.measure.moments_coords_central。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。