Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在skimage/Python中,如何提及邻域计算glcm的方向?_Python_Scikit Image_Glcm - Fatal编程技术网

在skimage/Python中,如何提及邻域计算glcm的方向?

在skimage/Python中,如何提及邻域计算glcm的方向?,python,scikit-image,glcm,Python,Scikit Image,Glcm,我很难理解skimage中greycomatrix的angle参数。在中提到的示例中,为了计算右侧和上方像素的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

我很难理解skimage中
greycomatrix
angle
参数。在中提到的示例中,为了计算右侧和上方像素的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)

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

在(强调我的)示例中有一个输入错误:

示例

计算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,距离和角度值应分别为
1
0

result = greycomatrix(image, distances=[1], angles=[0], levels=4)
而要计算对应于“1像素向上偏移”的GLCM,参数应为
1
np.pi/2

result = greycomatrix(image, distances=[1], angles=[np.pi/2], levels=4)
在本例中,
距离=[1]
角度=[0,np.pi/4,np.pi/2,3*np.pi/4]
。要选择特定的GLCM,必须为
角度
距离
指定适当的索引。因此,右侧的1像素GLCM是
result[:,:,0,0]
,向上的1像素GLCM是
result[:,:,0,2]


最后,如果您希望计算“向下1像素偏移”GLCM(↓) 您只需将“1像素向上偏移”GLCM转置即可(↑). 需要注意的是,在大多数情况下,两个GLCM都非常相似。事实上,在调用
greycomatrix
时,通过将参数
symmetric
设置为
True
,可以忽略共现强度的顺序。这样一来,
greycomatrix
返回的所有GLCM都是对称的。

当前正在尝试解决这个问题。您是否也可以扩展“levels”参数?根据skimage:输入图像应包含[0,levels-1]中的整数,其中levels表示计数的灰度级数(对于8位图像通常为256)。对于16位或更高的图像,此参数是必需的,通常是图像的最大值。由于输出矩阵至少为级别x级别,因此最好使用输入图像的分块,而不是级别的大值。
levels
的值决定灰度共生矩阵的大小。您可能希望o深入了解
级别
参数。谢谢-真的很有用。我的图像中有很多黑色空间,我不完全确定发生了什么,所以我将在此发布一个新问题。我发布了以下内容:-如果你能看一下的话