【问题标题】:Scikit-image and central moments: what is the meaning?Scikit-image 和中心时刻:意义何在?
【发布时间】:2016-08-08 16:42:09
【问题描述】:

在寻找如何使用图像处理工具“描述”任何类型的图像和形状的示例时,我偶然发现了 Scikit-image skimage.measure.moments_central(image, cr, cc, order=3) 函数。

他们举了一个如何使用这个功能的例子:

from skimage import measure #Package name in Enthought Canopy
import numpy as np

image = np.zeros((20, 20), dtype=np.double) #Square image of zeros
image[13:17, 13:17] = 1 #Adding a square of 1s
m = moments(image)
cr = m[0, 1] / m[0, 0] #Row of the centroid (x coordinate)
cc = m[1, 0] / m[0, 0] #Column of the centroid (y coordinate)

In[1]: moments_central(image, cr, cc)
Out[1]:
array([[ 16.,   0.,  20.,   0.],
       [  0.,   0.,   0.,   0.],
       [ 20.,   0.,  25.,   0.],
       [  0.,   0.,   0.,   0.]])

1)每个值代表什么?由于(0,0)元素是16,我得到这个数字对应于1s平方的面积,因此它是mu零零。但是其他人呢?

2) 这总是对称矩阵吗?

3) 与著名的第二中心矩相关的值是什么?

【问题讨论】:

标签: python image-processing canopy scikit-image


【解决方案1】:

measure.moments_central返回的数组对应https://en.wikipedia.org/wiki/Image_moment(截面中心矩)的公式。 mu_00 确实对应对象的面积。

惯性矩阵并不总是对称的,如本例所示,对象是矩形而不是正方形。

>>> image = np.zeros((20, 20), dtype=np.double) #Square image of zeros
>>> image[14:16, 13:17] = 1
>>> m = measure.moments(image)
>>> cr = m[0, 1] / m[0, 0]
>>> cc = m[1, 0] / m[0, 0]
>>> measure.moments_central(image, cr, cc)
array([[  8. ,   0. ,   2. ,   0. ],
       [  0. ,   0. ,   0. ,   0. ],
       [ 10. ,   0. ,   2.5,   0. ],
       [  0. ,   0. ,   0. ,   0. ]])

对于二阶矩,它们是 mu_02、mu_11 和 mu_20(对角线上的系数 i + j = 1)。同一维基百科页面https://en.wikipedia.org/wiki/Image_moment 解释了如何使用二阶矩来计算对象的方向。

【讨论】:

  • 谢谢。我不必参考维基百科——我已经这样做了——我期望从包本身获得更多信息。幸好有人提出了问题。所以根据你的回答,mu_02、mu_11 和 mu_20 分别是第一行的最后一个元素和第二行的前两个。对吗?
  • 当然包的文档需要改进。 mu_ij 是第 i_ 行第 j 列的元素(索引从 0 开始),因此 mu_02 是第 0 行和第 2 列的元素(在我之前的示例中为 2),mu_11 是第一行和第一列的元素( 0)等
  • 我得到这些索引在二维笛卡尔空间中也有含义(例如,第一个索引指的是 x 轴,第二个索引指的是 y 轴)。对吗?
猜你喜欢
  • 2015-01-20
  • 1970-01-01
  • 2017-04-21
  • 2021-04-10
  • 2018-08-03
  • 2019-09-12
  • 2021-06-17
  • 1970-01-01
相关资源
最近更新 更多