python灰度共生矩阵GLCM,带公式和代码

python灰度共⽣矩阵GLCM,带公式和代码
灰度共⽣矩阵所代表的含义是图像的灰度值在空间的某个⽅向上的特点,但是如何衡量两个⽬标图像纹理之间的差异是不能直接使⽤灰度共⽣矩阵表⽰出来的,所以需要使⽤⼀个特定的模型去统计灰度共⽣矩阵的特性来描述纹理特性。例如Haralick HaralickHaralick曾提出了14种基于灰度共⽣矩阵计算出来的统计量:能量、熵、对⽐度、均匀性、相关性、⽅差、和平均、和⽅差、和熵、差⽅差、差平均、差熵、相关信息测度以及最⼤相关系数。
1. 逆差矩(HOMO):测量灰度图像的局部强度的均匀性,如果局部均匀,逆差矩值较⼤。
2. ⼆阶矩(ASM):⼜称能量,是图像均匀性的测度,图像的灰度分布越均匀的,相应的ASM值越⼤,反之,ASM越⼩。
3. 熵(ENT):是衡量⽬标图像信息量多少的量,其中纹理信息也是熵衡量的⼀个⽅⾯。当图像中元素⽐较分散时,熵越⼤,反之越⼩。熵的⼤⼩代表了⽬标图像纹理的均匀程度或复杂程度。
4. 对⽐度(CON):反映局部图像灰度变化程度,图像中灰度值差别越⼤,则图像边缘也越锐利,对⽐度也就越⼤,典型的k=2,λ=1。
5. 差异性(DISL):和对⽐度的衡量类似,但是差异性对于局部特点衡量性较好,当局部对⽐度增加,那么差异性也随之增加。
6. 相关性(COR):表⽰⽬标图像的灰度像素成线性关系的度量,代表灰度共⽣矩阵⾏列灰度关系的相似度。
考虑到算法的时效性,我们经常要通过实验对⽐并选取合适的特征。在选择时⼀般是要先通过项⽬的实际情况,⼤致选定⼏类特征,然后进⾏实验对⽐,最终选择耗时短,且能达到项⽬要求的特征。我们可以根据公式⾃⼰写代码,但很可能会耗费⽐较多的时间去运⾏。⼩⽩可以才考下⾯在github上开源的代码,直接调⽤封装好的函数,可能会快⼀点。代码链接是:
拉曼光谱分析import numpy as np
from skimage.feature import greycomatrix, greycoprops
现代货币数量论成都体育学院图书馆from skimage import io, color, img_as_ubyte
img = io.imread('image_sample.jpg')
gray = b2gray(img)
image = img_as_ubyte(gray)
bins = np.array([0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 255]) #16-bit
inds = np.digitize(image, bins)
max_value = inds.max()+1
matrix_coocurrence = greycomatrix(inds, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=max_value, normed=False, symmetric=False)
# GLCM properties
def contrast_feature(matrix_coocurrence):
永磁同步电机contrast = greycoprops(matrix_coocurrence, 'contrast')
return "Contrast = ", contrast
def dissimilarity_feature(matrix_coocurrence):
dissimilarity = greycoprops(matrix_coocurrence, 'dissimilarity')
return "Dissimilarity = ", dissimilarity
def homogeneity_feature(matrix_coocurrence):
homogeneity = greycoprops(matrix_coocurrence, 'homogeneity')
return "Homogeneity = ", homogeneity
def energy_feature(matrix_coocurrence):
energy = greycoprops(matrix_coocurrence, 'energy')
return "Energy = ", energy
def correlation_feature(matrix_coocurrence):
过氧乙酸
correlation = greycoprops(matrix_coocurrence, 'correlation')
return "Correlation = ", correlationt5荧光灯
def asm_feature(matrix_coocurrence):
asm = greycoprops(matrix_coocurrence, 'ASM')
return "ASM = ", asm
print(contrast_feature(matrix_coocurrence))
print(dissimilarity_feature(matrix_coocurrence))
print(homogeneity_feature(matrix_coocurrence))
print(energy_feature(matrix_coocurrence))
print(correlation_feature(matrix_coocurrence))
print(asm_feature(matrix_coocurrence))

本文发布于:2024-09-24 05:23:15,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/104944.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:灰度   图像   矩阵   局部
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议