我怎么提到邻居的方向来计算skimage / Python中的glcm?

时间:2016-06-11 08:05:29

标签: python scikit-image glcm

我很难理解skimage中greycomatrix的{​​{1}}参数。在documentation中提到的用于向右和向上计算像素的GLCM的示例中,它们提到了4个角度。他们得到了4个GLCM。

>>> image = np.array([[0, 0, 1, 1],
...                   [0, 0, 1, 1],
...                   [0, 2, 2, 2],
...                   [2, 2, 3, 3]], dtype=np.uint8)
>>> result = greycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=4)

像素向右和向下的参数应该是什么?

1 个答案:

答案 0 :(得分:1)

documentation of greycomatrix(强调我的)中包含的示例中有一个拼写错误:

  

示例

     

计算 2 GLCM :一个用于向右1像素偏移,一个用于向上1像素偏移。

>>> image = np.array([[0, 0, 1, 1],  
...                   [0, 0, 1, 1],
...                   [0, 2, 2, 2],
...                   [2, 2, 3, 3]], dtype=np.uint8)
>>> result = greycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4],
...                       levels=4)

实际上,result实际上包含四个不同的GLCM 而不是两个。这四个矩阵对应于一个距离和四个角度的可能组合。要计算与“向右1个像素偏移”对应的GLCM,距离和角度值应分别为10

result = greycomatrix(image, distances=[1], angles=[0], levels=4)

而要计算与“1像素偏移向上”对应的GLCM,参数应为1np.pi/2

result = greycomatrix(image, distances=[1], angles=[np.pi/2], levels=4)

在示例中,distances=[1]angles=[0, np.pi/4, np.pi/2, 3*np.pi/4]。要选择特定的GLCM,必须为anglesdistances指定适当的索引。因此,1像素到右GLCM为result[:, :, 0, 0],1像素向上GLCM为result[:, :, 0, 2]

最后,如果您希望计算“向下1像素偏移” GLCM(↓),您只需将“1像素偏移向上”转换为 GLCM (↑)。值得注意的是,在大多数情况下,两个GLCM非常相似。实际上,您可以通过在symmetric的调用中将参数True设置为greycomatrix来忽略同时发生的强度的顺序。通过这样做,greycomatrix返回的GLCM是对称的。