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


Python skimage.feature.graycomatrix用法及代碼示例

用法:

skimage.feature.graycomatrix(image, distances, angles, levels=None, symmetric=False, normed=False)

計算灰度共生矩陣。

灰度共生矩陣是圖像上給定偏移量處co-occurring 灰度值的直方圖。

參數

imagearray_like

整數類型的輸入圖像。僅支持正值圖像。如果 type 不是 uint8,則需要設置參數級別。

distancesarray_like

像素對距離偏移列表。

anglesarray_like

以弧度為單位的像素對角度列表。

levelsint 可選

輸入圖像應包含 [0, levels-1] 中的整數,其中級別表示計數的灰度級數(對於 8 位圖像,通常為 256)。此參數對於 16 位或更高位的圖像是必需的,通常是圖像的最大值。由於輸出矩陣至少為 x 個級別,因此最好使用輸入圖像的分箱而不是較大的級別值。

symmetric布爾型,可選

如果為 True,則輸出矩陣 P[:,:, d, theta] 是對稱的。這是通過忽略值對的順序來完成的,因此當遇到給定偏移量的 (i, j) 時, (i, j) 和 (j, i) 都會累加。默認值為假。

normed布爾型,可選

如果為真,則通過除以給定偏移量的累積共現總數來歸一化每個矩陣 P[:,:, d, theta]。結果矩陣的元素總和為 1。默認值為 False。

返回

P4-D ndarray

灰度共現直方圖。值 P[i,j,d,theta] 是灰度 j 在距離 d 處和與灰度 i 成角度 theta 處出現的次數。如果 normed 為 False,則輸出類型為 uint32,否則為 float64。維度是:級別 x 級別 x 距離數 x 角度數。

參考

1

M. Hall-Beyer, 2007. GLCM Texture: A Tutorial https://prism.ucalgary.ca/handle/1880/51900 DOI:10.11575/PRISM/33280

2

R.M. Haralick, K. Shanmugam, and I. Dinstein, “Textural features for image classification”, IEEE Transactions on Systems, Man, and Cybernetics, vol. SMC-3, no. 6, pp. 610-621, Nov. 1973. DOI:10.1109/TSMC.1973.4309314

3

M. Nadler and E.P. Smith, Pattern Recognition Engineering, Wiley-Interscience, 1993.

4

Wikipedia, https://en.wikipedia.org/wiki/Co-occurrence_matrix

例子

計算 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 = graycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4],
...                       levels=4)
>>> result[:, :, 0, 0]
array([[2, 2, 1, 0],
       [0, 2, 0, 0],
       [0, 0, 3, 1],
       [0, 0, 0, 1]], dtype=uint32)
>>> result[:, :, 0, 1]
array([[1, 1, 3, 0],
       [0, 1, 1, 0],
       [0, 0, 0, 2],
       [0, 0, 0, 0]], dtype=uint32)
>>> result[:, :, 0, 2]
array([[3, 0, 2, 0],
       [0, 2, 2, 0],
       [0, 0, 1, 2],
       [0, 0, 0, 0]], dtype=uint32)
>>> result[:, :, 0, 3]
array([[2, 0, 0, 0],
       [1, 1, 2, 0],
       [0, 0, 2, 1],
       [0, 0, 0, 0]], dtype=uint32)

相關用法


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