Sre*_*non 10 python numpy entropy scikit-image glcm
我正在使用skimage
库进行大多数图像分析工作.
我有一个RGB图像,我打算提取texture
喜欢的功能entropy
,energy
,homogeneity
并contrast
从图像.
以下是我正在执行的步骤:
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.
Run Code Online (Sandbox Code Playgroud)
我的问题是,从灰度图像(直接)计算的熵是否与从GLCM(纹理特征)中提取的熵特征相同?
如果没有,从图像中提取所有纹理特征的正确方法是什么?
注:我已经提到过:
Ton*_*has 16
来自灰度图像的计算熵(直接)是否与从GLCM(纹理特征)中提取的熵特征相同?
不,这两个熵是相当不同的:
skimage.filters.rank.entropy(grayImg, disk(5))
产生一个相同大小的数组,grayImg
其中包含在圆盘上计算的图像上的局部熵,其中心位于相应的像素,半径为5像素.看看熵(信息理论),找出如何计算熵.此数组中的值对于分段很有用(请点击此链接查看基于熵的对象检测的示例).如果您的目标是通过您可以使用的单个(标量)值来描述图像的熵skimage.measure.shannon_entropy(grayImg)
.此功能基本上将以下公式应用于完整图像: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])
Run Code Online (Sandbox Code Playgroud)
使用此图像获得的结果:
:
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]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9209 次 |
最近记录: |