问题描述
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,dissimilarity = get_texture_glcm (ht_mean)
return contrast,dissimilarity
2 - 除了了解我是否正确思考了上面的代码之外,我还需要基于 GLCM 计算 Haralick 的熵,为此,我明白我可以使用 SCIPY 函数或实现 SHANNON 熵,如下所述:
Calculating entropy from GLCM of an image https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html
对于我想要实现的 Haralick 来说,考虑这个熵是否合适?
entropy = scipy.stats.entropy (ma_hist)
感谢您愿意提供帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)