灰度共生矩阵greycomatrix()参数详解

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]]

....此处省略
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值