【问题标题】:Calculating entropy from GLCM of an image从图像的 GLCM 计算熵
【发布时间】:2017-04-16 15:21:21
【问题描述】:

我使用skimage 库进行大部分图像分析工作。

我有一个 RGB 图像,我打算从图像中提取 texture 特征,如 entropyenergyhomogeneitycontrast

以下是我正在执行的步骤:

from skimage import io, color, feature
from skimage.filters import rank
rgbImg = io.imread(imgFlNm)
grayImg = color.rgb2gray(rgbImg)
print(grayImg.shape)  # (667,1000), a 2 dimensional grayscale image

glcm = feature.greycomatrix(grayImg, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4])
print(glcm.shape) # (256, 256, 1, 4)

rank.entropy(glcm, disk(5)) # throws an error since entropy expects a 2-D array in its arguments

rank.entropy(grayImg, disk(5)) # given an output.

我的问题是,从灰度图像(直接)计算的熵是否与从 GLCM(纹理特征)中提取的熵特征相同?

如果不是,从图像中提取所有纹理特征的正确方法是什么?

备注:我已经提到过:

Entropy - skimage

GLCM - Texture features

【问题讨论】:

    标签: python numpy entropy scikit-image glcm


    【解决方案1】:

    从灰度图像(直接)计算的熵是否与从 GLCM 提取的熵特征(纹理特征)相同?

    不,这两个熵相当不同:

    1. skimage.filters.rank.entropy(grayImg, disk(5)) 产生一个与 grayImg 大小相同的数组,其中包含在圆盘上计算的图像的局部熵,圆盘的中心位于相应的像素,半径为 5 个像素。查看Entropy (information theory) 了解如何计算熵。该数组中的值对分割很有用(关注this link 以查看基于熵的对象检测的示例)。如果您的目标是通过单个(标量)值描述图像的熵,您可以使用skimage.measure.shannon_entropy(grayImg)。此函数基本上将以下公式应用于完整图像:

      其中 是灰度级数(8 位图像为 256), 是像素具有灰度级 的概率, 是对数函数的底。当 设置为 2 时,返回值以 bits 为单位。
    2. 灰度共生矩阵 (GLCM) 是图像上给定偏移量处共生灰度值的直方图。为了描述图像的纹理,通常从针对不同偏移量计算的几个共现矩阵中提取特征,例如熵、能量、对比度、相关性等。在这种情况下,熵定义如下:

      其中 再次分别是灰度级数和对数函数的基数, 代表由指定偏移量分隔的两个像素具有强度 的概率.不幸的是,熵不是您可以通过 scikit-image 计算的 GLCM 的属性之一*。如果您希望计算此功能,您需要将 GLCM 传递给 skimage.measure.shannon_entropy

    *在本文最后一次编辑时,scikit-image 的最新版本是 0.13.1。

    如果不是,从图像中提取所有纹理特征的正确方法是什么?

    描述图像纹理的特征有很多种,例如局部二值模式、Gabor 滤波器、小波、Laws 掩码等。 Haralick 的GLCM 是最流行的纹理描述符之一。通过 GLCM 特征描述图像纹理的一种可能方法是计算不同偏移量的 GLCM(每个偏移量通过距离和角度定义),并从每个 GLCM 中提取不同的属性。

    让我们考虑例如三个距离(1、2 和 3 像素)、四个角度(0、45、90 和 135 度)和两个属性(能量和同质性)。这导致 偏移量(因此有 12 个 GLCM)和维度为 的特征向量。代码如下:

    import numpy as np
    from skimage import io, color, img_as_ubyte
    from skimage.feature import greycomatrix, greycoprops
    from sklearn.metrics.cluster import entropy
    
    rgbImg = io.imread('https://i.stack.imgur.com/1xDvJ.jpg')
    grayImg = img_as_ubyte(color.rgb2gray(rgbImg))
    
    distances = [1, 2, 3]
    angles = [0, np.pi/4, np.pi/2, 3*np.pi/4]
    properties = ['energy', 'homogeneity']
    
    glcm = greycomatrix(grayImg, 
                        distances=distances, 
                        angles=angles,
                        symmetric=True,
                        normed=True)
    
    feats = np.hstack([greycoprops(glcm, prop).ravel() for prop in properties])
    

    使用此图像获得的结果:

    :

    In [56]: entropy(grayImg)
    Out[56]: 5.3864158185167534
    
    In [57]: np.set_printoptions(precision=4)
    
    In [58]: print(feats)
    [ 0.026   0.0207  0.0237  0.0206  0.0201  0.0207  0.018   0.0206  0.0173
      0.016   0.0157  0.016   0.3185  0.2433  0.2977  0.2389  0.2219  0.2433
      0.1926  0.2389  0.1751  0.1598  0.1491  0.1565]
    

    【讨论】:

    • 我想知道在设置normed=True 时将glcm 传递给skimage.measure.shannon_entropy() 是否正确?我们为什么不使用normed=False
    • 为了使熵公式成立,p(·) 必须是概率,即 GLCM 条目的总和必须为 1。这就是为什么参数 normed 必须设置为 @987654365 @
    【解决方案2】:
    from skimage.feature import greycomatrix, greycoprops
    
        dis = (greycoprops(glcm, 'dissimilarity'))
        plt.hist(dis.ravel(), normed=True, bins=256, range=(0, 30),facecolor='0.5');plt.show()
    

    【讨论】:

    • 你能详细说明你的答案吗?解释一下您要绘制的内容?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-30
    • 2015-01-31
    相关资源
    最近更新 更多