GLCM提取纹理特征还是很厉害的!尤其是和LBP相结合来使用
GLCM中有很多属性可以选择,大家可以选择适合自己数据集的最优的属性组合。
第一步:获取图像的灰度图
"files[i]为输入的图像路径"
"as_grey = True表示转换为灰度图"
"返回图像数组,其中每个值的类型为float64,范围为[0,1],分布不均匀"
image = skimage.data.load(files[i], as_grey = True)

[图片上传中...(image-6d351-1589296727210-17)]

第二步:图像有可能相同像素值的点很多,为了增加图像的对比度和清晰度,需要直方图均衡化。

"image 为输入的图像数组"
"nbins = 256表示像素值的柱数,可使得图形数组中的数值可在[0,1]之间有256个间隙可选"
"返回图像数组,其中每个值的类型为float64,范围为[0,1],分布均匀"
window = skimage.exposure.equalize_hist(image , nbins = 256)



第三步:float转8位无符号整数,可表示的范围就是[0,255]
"输入:float类型的图像数组,范围为[0,1]"
"输出:图像数组,范围[0,255]"
window = skimage.util.img_as_ubyte(skimage.exposure.equalize_hist(window, 256))



第四步:转化到[1,8]
"window为输入的图像数组,范围[0,255]"
"bins = np.arange(0, 256, 32)为一维单调数组"
"返回值:x在bins中的位置"
np.digitize(window, bins = np.arange(0, 256, 32))





第五步:转化到[0,7]即8位无符号整数
wt = (np.digitize(window, np.arange(0, 256, 32))) - 1



网友评论