所以我正在阅读一篇研究论文 [链接],其中包含以下用于获取图像纹理的算法。
所以我从上面的算法中了解到,我需要制作 4x4 的网格并找到每个 4x4 子矩阵的 GLCM 矩阵,然后计算属性。
但是我对这种方法的问题是图像的大小为 256x384,它给出了 64*96 的网格,计算 GLCM 矩阵 64*96 次的计算量非常大,特别是因为我有 900 个这样的图像。
代码如下:
def texture_extract(img):
distance = [1]
angles = [0, np.pi/4, np.pi/2, 3*np.pi/4]
properties = ['correlation', 'homogeneity', 'contrast', 'energy', 'dissimilarity']
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray_img, (5,5), 0)
texture_features = []
for i in range(0, blur.shape[0], 4):
for j in range(0, blur.shape[1], 4):
block = blur[i:i+4, j:j+4]
glcm_mat = greycomatrix(block, distances=distance, angles=angles, symmetric=True, normed=True)
block_glcm = np.hstack([greycoprops(glcm_mat, props).ravel() for props in properties])
texture_features.append(block_glcm)
return np.concatenate(texture_features)
我只想知道,我对算法的理解是正确的,还是我在某个地方犯了一个愚蠢的错误。