Python批量提取图像灰度共生矩阵(GLCM)、支持批量处理、任意图像格式

目录

一、介绍

二、实现

1、特征计算

2、批量处理

3、结果


一、介绍

灰度共生矩阵(Grey Level Co-occurrence Matrix)也叫做空间灰度级依赖矩阵(SGLDM),它是一种基于统计的纹理特征提取的方法。

一般包括四个方向:

  • (a,b)=(1,0),像素对是水平的,即0度扫描;
  • (a,b)=(0,1),像素对是垂直的,即90度扫描;
  • (a,b)=(1,1),像素对是右对角线的,即45度扫描;
  • (a,b)=(-1,1),像素对是左对角线,即135度扫描。

一般包括8个常用特征:均值、方差、角二阶矩、熵、对比度、相关性、Homogeneity、Dissimilarity

二、实现

1、特征计算

python 复制代码
# 建立特征函数索引
indexs = {0:calculate_gray_co_occurrence_matrix_entropy, # 熵
          1:calculate_gray_co_occurrence_matrix_mean, # 均值
          2:calculate_gray_co_occurrence_matrix_variance, # 方差
          3:calculate_gray_co_occurrence_matrix_homogeneity, # homogeneity
          4:calculate_gray_co_occurrence_matrix_contrast, # contrast
          5:calculate_gray_co_occurrence_matrix_dissimilarity, # Dissimilarity
          6:calculate_gray_co_occurrence_matrix_energy, # 能量or角二阶
          7:calculate_gray_co_occurrence_matrix_correlation, # 相关性
          8:calculate_gray_co_occurrence_matrix_autocorrelation # 自相关性
          }

2、批量处理

其中 .jpg 修改为自己文件的后缀

python 复制代码
if __name__=="__main__":
    path = r"./data"
    save_ = r"./texture"

    file_list = os.listdir(path)
    for i in file_list:
        if os.path.splitext(i)[1] == ".jpg":
            print("正在处理文件:", i)

            file_path = path + "/" + i
            glcm = glcm_features(file_path)
            print(glcm.shape)
            utils.save_img(glcm, save_+"/" + os.path.splitext(i)[0] +'.tif')

3、结果

我们提取下面的图像:

只提取均值这个特征:

代码链接:Python批量提取图像灰度共生矩阵(GLCM)、支持批量处理、任意图像格式

相关推荐
网安INF1 分钟前
【论文阅读】-《HopSkipJumpAttack: A Query-Efficient Decision-Based Attack》
论文阅读·人工智能·深度学习·网络安全·对抗攻击
你知道网上冲浪吗17 分钟前
【原创理论】Stochastic Coupled Dyadic System (SCDS):一个用于两性关系动力学建模的随机耦合系统框架
python·算法·数学建模·数值分析
钢铁男儿21 分钟前
Python 正则表达式核心元字符全解析
python
杨荧1 小时前
基于Python的宠物服务管理系统 Python+Django+Vue.js
大数据·前端·vue.js·爬虫·python·信息可视化
CodeCraft Studio1 小时前
在 Python 中操作 Excel 文件的高效方案 —— Aspose.Cells for Python
python·ui·excel·报表·aspose·aspose.cells
l1t1 小时前
利用DeepSeek辅助WPS电子表格ET格式分析
人工智能·python·wps·插件·duckdb
plusplus1682 小时前
边缘智能实战手册:攻克IoT应用三大挑战的AI战术
人工智能·物联网
果粒橙_LGC2 小时前
论文阅读系列(一)Qwen-Image Technical Report
论文阅读·人工智能·学习
WSSWWWSSW2 小时前
Matplotlib数据可视化实战:Matplotlib子图布局与管理入门
python·信息可视化·matplotlib
WSSWWWSSW2 小时前
Matplotlib数据可视化实战:Matplotlib图表美化与进阶教程
python·信息可视化·matplotlib