1. 参数
greycomatrix(image, distances, angles, levels=None, symmetric=False,normed=False)
#分别为:图片,距离(需要为列表),角度(列表),灰度等级
#1.返回值:
P : N-D ndarray,levels=N
#2.symmetric :
如果为真,则输出矩阵P[:, :, d, theta]是对称的。这一点是通过忽略数值对的顺序来实现的.
#3.normed:
如果是 “真”,则对每个矩阵P[:, :, d, theta]进行规范化处理,方法是将其除以除以给定偏移量的累计贡献总数。所得矩阵的元素之和为1。
#4.传参要求
greycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4],
… levels=4
levels:级别数应该大于图像中的最大灰度值.
2.偏移量与距离的变化造成返回值格式的变化
#首先导入相关包,举例
import numpy as np
from skimage.feature import greycomatrix, greycoprops
import cv2
import os
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
gray = np.random.randint(0,255,(10,10))
'''将图片的256阶化为 8个等级,指将像素值划分到0-7'''
gray_8 = (gray/32).astype(np.int32)
#输入(1)
Glcm0 = greycomatrix(gray_8,[1],[0],levels=8)
Glcm_0 = Glcm0.squeeze() #squeeze 函数:从数组的形状中删除单维度条目,即把shape中为1的维度去掉,没必要的维度去掉,类似[[[1,2]]]只需要保留一个维度
print("输出Glcm_0.shape与Glcm_0")
print(Glcm_0.shape,Glcm_0)
#输出(1)
(8, 8)
[[3 2 3 0 1 1 0 1]
[1 1 2 2 1 1 1 1]
[0 1 2 2 4 2 1 2]
[1 1 0 2 2 2 1 0]
[1 2 4 2 5 3 0 2]
[2 1 2 0 3 2 1 1]
[0 2 0 2 0 1 0 0]
[2 1 3 0 2 1 0 1]]
输入(2)
Glcm1 = greycomatrix(gray_8,[1],[0,np.pi/4],levels=8)
Glcm_1 = Glcm1.squeeze()
print("输出Glcm_1.shape与Glcm_1")
print(Glcm_1.shape,Glcm_1)
输出(2)
输出Glcm_1.shape与Glcm_1
(8, 8, 2)
[[[3 1]
[2 1]
[3 2]
[0 1]
[1 1]
[1 2]
[0 1]
[1 0]]
[[1 0]
[1 3]
[2 0]
[2 1]
[1 3]
[1 1]
[1 0]
[1 0]]
[[0 2]
[1 0]
[2 2]
[2 1]
[4 4]
[2 2]
[1 0]
[2 0]]
[[1 1]
[1 0]
[0 1]
[2 1]
[2 1]
[2 3]
[1 0]
[0 2]]
[[1 1]
[2 1]
[4 3]
[2 4]
[5 6]
[3 2]
[0 0]
[2 1]]
[[2 3]
[1 2]
[2 3]
[0 0]
[3 0]
[2 1]
[1 1]
[1 2]]
[[0 0]
[2 1]
[0 0]
[2 0]
[0 0]
[1 1]
[0 1]
[0 1]]
[[2 1]
[1 1]
[3 3]
[0 1]
[2 2]
[1 0]
[0 1]
[1 1]]]
#输入(3)
Glcm2 = greycomatrix(gray_8,[0,2,8],[0,np.pi/4,np.pi/2],levels=8)
Glcm_2 = Glcm2.squeeze()
print("输出Glcm_2.shape与Glcm_2")
print(Glcm_2.shape,Glcm_2)
#输出(3)
输出Glcm_2.shape与Glcm_2
(8, 8, 3, 3)
[[[[13 13 13]
[ 1 1 0]
[ 1 0 1]]
[[ 0 0 0]
[ 1 1 2]
[ 2 1 1]]
[[ 0 0 0]
[ 2 2 0]
[ 0 0 1]]
[[ 0 0 0]
[ 2 1 0]
[ 1 0 0]]
[[ 0 0 0]
[ 2 1 1]
[ 0 1 0]]
....此处省略
文章来源地址https://www.toymoban.com/news/detail-649080.html
文章来源:https://www.toymoban.com/news/detail-649080.html
到了这里,关于灰度共生矩阵greycomatrix()参数详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!