python - 提取 GLCM 特征
问题描述
所以我正在阅读一篇研究论文 [链接],其中包含以下用于获取图像纹理的算法。
所以我从上面的算法中了解到,我需要制作 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)
我只想知道,我对算法的理解是正确的,还是我在某个地方犯了一个愚蠢的错误。
解决方案
推荐阅读
- html - 数字输入 - 文本略低于中心,直到您单击框
- python - Python 中的数据类型不匹配尝试使用一些 twitter 数据更新 Sqlite3 数据库
- sql - 访问追加查询重复结果
- android - 如何从使用 create-react-native-app 构建的 Android 应用程序中删除短信和通话权限?
- html - 隐藏在内容后面的子菜单
- python - Tkinter - 我如何更改标题?
- php - 我的 SQL 查询在 PHP 上是错误的,但在 phpmyadmin 上有效
- java - 如何在不使用正则表达式的情况下检查字符串格式?
- php - 如何使用 Slim Router 在 PHP MVC 中向用户显示错误消息?
- java - Apache Beam TextIO.ReadAll 如何发出 KeyValue 而不是 Pcollection 的字符串