1 - 我正在提取超像素的特征,我需要实现的提取之一是从灰度共生矩阵 GLCM(灰度共生矩阵)中提取 Haralick 特征。在这个意义上,我明白了,首先我必须提取 Haralick,然后将其应用到 GLCM 以找到我需要的对比度、能量等特征,但我不知道我是否真的正确。如果有道理,你能帮我吗?
# GLCM
def get_texture_glcm (img):
# convert to gray
gray = cv2.cvtColor (img, cv2.COLOR_BGR2GRAY)
distances = [1, 2, 3]
angles = [0, np.pi / 4, np.pi / 2, 3 * np.pi / 4]
glcm = greycomatrix (gray,
distances = distances,
angles = angles,
symmetric = True,
normed = True)
properties = ['contrast', 'energy', 'homogeneity', 'correlation', 'dissimilarity']
contrast = greycoprops (glcm, properties [0])
energy = greycoprops (glcm, properties [1])
homogeneity = greycoprops (glcm, properties [2])
correlation = greycoprops (glcm, properties [3])
dissimilarity = greycoprops (glcm, properties [4])
contrast = greycoprops (glcm, properties [0]). mean (axis = 1)
return contrast, energy, homogeneity, correlation, dissimilarity
# HARALICK
def get_texture_haralick (image):
print ("[STATUS] Started extracting haralick textures ...")
# function to extract haralick textures from an image
# calculate haralick texture features for 4 types of adjacency
textures = mh.features.haralick (image)
# take the mean of it and return it
ht_mean = textures.mean (axis = 0)
contrast, energy, homogeneity, correlation, dissimilarity = get_texture_glcm (ht_mean)
return contrast, energy, homogeneity, correlation, dissimilarity
2 - 除了了解我是否正确考虑了上面的代码之外,我还需要根据 GLCM 计算 Haralick 的熵,为此,我知道我可以使用 SCIPY 函数或实现 SHANNON ENTROPY,如下所述:
从图像的 GLCM 计算熵 https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html
我想实现的 Haralick 考虑这个熵是否合适?
entropy = scipy.stats.entropy (ma_hist)
感谢您愿意提供帮助。