从图像的GLCM计算熵

问题描述:

我正在使用skimage库进行大部分图像分析工作。从图像的GLCM计算熵

我有一个RGB图像,我打算以提取像entropyenergy,从图像homogeneitycontrasttexture特征。

下面是我执行以下步骤:

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. 

我的问题是,从灰度图像所计算的熵(直接地)与从灰度共生矩阵中提取的熵特征(纹理特征)?

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

注:我已经提到:

Entropy - skimage

GLCM - Texture features

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

否,这两种熵是相当不同的:

  1. skimage.filters.rank.entropy(grayImg, disk(5))生成一个数组的大小grayImg包含跨其在相应的像素计算出的圆盘上具有中心的图像的局部熵相同和半径5个像素。看看Entropy (information theory)来了解熵是如何计算的。此数组中的值对于分割很有用(请参阅this link以查看基于熵的对象检测的示例)。如果您的目标是通过单个(标量)值来描述图像的熵,那么您可以使用skimage.measure.shannon_entropy(grayImg)。此功能主要适用以下公式来完整的图像:
    entropy
    其中n是灰度级(256为8位的图像)的数量,probability是具有灰度级intensity的像素的概率,和base是对数函数的基础。当base设置为2时,返回的值在中测量。
  2. 灰度共生矩阵(GLCM)是图像上给定偏移处的共生灰度值的直方图。为了描述图像的纹理,通常从针对不同偏移计算的多个共现矩阵中提取诸如熵,能量,对比度,相关性等的特征。在此情况下,熵的定义如下:
    entropy of GLCM
    其中nbase再次是偏移的灰度级的数目和分别对数函数,的基极,和GLCM element代表由指定的分开的两个像素的概率其强度为intensityj。不幸的是熵不是GLCM的属性之一,你可以通过scikit-image来计算*。如果你想计算这个功能,你需要通过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偏移量(因此导致12个GLCM)以及尺寸为24的特征向量。下面的代码:使用该图像获得

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]) 

结果:

sample image - lion

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] 
+0

非常感谢!这有助于.. –

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() 
+1

你能对你的回答详细点吗?解释你想要展示什么? –