从灰度图像(直接)计算的熵是否与从 GLCM(纹理特征)中提取的熵特征相同?
不,这两个熵是完全不同的:
skimage.filters.rank.entropy(grayImg, disk(5))
产生一个大小相同的数组,该数组grayImg
包含在圆盘上计算的图像上的局部熵,圆盘的中心位于相应的像素,半径为 5 个像素。查看Entropy(信息论)以了解如何计算熵。此数组中的值对分割很有用(点击此链接可查看基于熵的对象检测示例)。如果您的目标是通过单个(标量)值来描述图像的熵,您可以使用skimage.measure.shannon_entropy(grayImg)
. 此函数基本上将以下公式应用于完整图像:
其中是灰度级数(8 位图像为 256),是像素具有灰度级的概率,以及




是对数函数的底。当
设置为 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]