从灰度图像(直接)计算出的熵与从 GLCM(纹理特征)提取的熵特征相同吗?
不,这两个熵相当不同:
-
skimage.filters.rank.entropy(grayImg, disk(5))
yields an array the same size as grayImg
which contains the local entropy across the image computed on a circular disk with center at the the corresponding pixel and radius 5 pixels. Take a look at Entropy (information theory) https://en.wikipedia.org/wiki/Entropy_(information_theory) to find out how entropy is calculated. The values in this array are useful for segmentation (follow this link http://scikit-image.org/docs/dev/auto_examples/filters/plot_entropy.html to see an example of entropy-based object detection). If your goal is to describe the entropy of the image through a single (scalar) value you can use skimage.measure.shannon_entropy(grayImg)
. This function basically applies the following formula to the full image:
where is the number of gray levels (256 for 8-bit images), is the probability of a pixel having gray level , and is the base of the logarithm function. When is set to 2 the returned value is measured in bits.
- A gray level co-occurence matrix (GLCM) is a histogram of co-occurring grayscale values at a given offset over an image. To describe the texture of an image it is usual to extract features such as entropy, energy, contrast, correlation, etc. from several co-occurrence matrices computed for different offsets. In this case the entropy is defined as follows:
where and are again the number of gray levels and the base of the logarithm function, respectively, and stands for the probability of two pixels separated by the specified offset having intensities and . Unfortunately the entropy is not one of the properties of a GLCM that you can calculate through scikit-image*. If you wish to compute this feature you need to pass the GLCM to skimage.measure.shannon_entropy http://scikit-image.org/docs/0.13.x/api/skimage.measure.html#skimage.measure.shannon_entropy.
*At the time this post was last edited, the latest version of scikit-image is 0.13.1.
如果不是,从图像中提取所有纹理特征的正确方法是什么?
描述图像纹理的特征有很多种,例如局部二值模式、Gabor 滤波器、小波、Laws 掩模等等。哈拉利克的GLCM http://www.ucalgary.ca/mhallbey/tutorial-glcm-texture是最流行的纹理描述符之一。通过 GLCM 特征描述图像纹理的一种可能方法包括计算不同偏移量的 GLCM(每个偏移量通过距离和角度定义),并从每个 GLCM 中提取不同的属性。
Let us consider for example three distances (1, 2 and 3 pixels), four angles (0, 45, 90 and 135 degrees) and two properties (energy and homogeneity). This results in offsets (and hence 12 GLCM's) and a feature vector of dimension . Here's the code:
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]