如何解决Python中图像的灰度Co发生矩阵
-
我正在获取图像的
Gray Level Co-occurrence Matrix
并使用计算该矩阵的Homogeneity
、Correlation
、Entropy
和Kurtosis
Python。 -
我从 skimage 导入了
greycomatrix
和greycoprops
并获得了GLCM
图像。
内置函数可以获取同质性和相关性,但没有获取熵和峰度的函数。
- 是否有任何内置或自定义代码来获取
Entropy
和kurtosis
,以便我可以修改我的 Python 代码,如下所示:
import numpy as np
from skimage.feature import greycomatrix,greycoprops
from skimage import io,color,img_as_ubyte
img = io.imread('ff.jpg')
gray = color.rgb2gray(img)
image = img_as_ubyte(gray)
io.imshow(image)
bins = np.array([0,16,32,48,64,80,96,112,128,144,160,176,192,208,224,240,255]) #16-bit
inds = np.digitize(image,bins)
max_value = inds.max()+1
matrix_coocurrence = greycomatrix(inds,[1],[0,np.pi/4,np.pi/2,3*np.pi/4],levels=max_value,normed=False,symmetric=False)
# GLCM properties
def contrast_feature(matrix_coocurrence):
contrast = greycoprops(matrix_coocurrence,'contrast')
return "Contrast = ",contrast
def dissimilarity_feature(matrix_coocurrence):
dissimilarity = greycoprops(matrix_coocurrence,'dissimilarity')
return "Dissimilarity = ",dissimilarity
def homogeneity_feature(matrix_coocurrence):
homogeneity = greycoprops(matrix_coocurrence,'homogeneity')
return "Homogeneity = ",homogeneity
def energy_feature(matrix_coocurrence):
energy = greycoprops(matrix_coocurrence,'energy')
return "Energy = ",energy
def correlation_feature(matrix_coocurrence):
correlation = greycoprops(matrix_coocurrence,'correlation')
return "Correlation = ",correlation
def entropy_feature(matrix_coocurrence):
entropy = greycoprops(matrix_coocurrence,'entropy')
return "Entropy = ",entropy
print(contrast_feature(matrix_coocurrence))
print(dissimilarity_feature(matrix_coocurrence))
print(homogeneity_feature(matrix_coocurrence))
print(energy_feature(matrix_coocurrence))
print(correlation_feature(matrix_coocurrence))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。