资源简介
自己用python写的灰度共生矩阵小程序
代码片段和文件信息
import cv2
import numpy
import math
image = cv2.imread(‘corn1.jpg‘)
blur = cv2.medianBlur(image3) #中值滤波
gray = cv2.cvtColor(blurcv2.COLOR_BGR2GRAY)#灰度化
h w = gray.shape[:2]
gray = numpy.insert(graywvalues=gray[:0]axis=1)
h1 w1 = gray.shape[:2]
#gray = numpy.array(gray)
#print(type(gray))
#存放相邻两个灰度值出现的概率
p = [[[0 for col in range(16)] for row in range(16)] for k in range(4)]
#灰度共生矩阵
CoefficientMat = numpy.zeros([1616])
#将灰度级(0255)转为灰度级为(015)
for i in range(h1):
for j in range(w1):
for n in range(16):
if (n*16 <= gray[ij]) and (gray[ij] <= n*16+15):
gray[ij] = n
if j >0 : #统计相邻两个灰度出现的频数,得到灰度共生矩阵 这里是去0度,即x和y是左右关系
x = gray[ij]
y = gray[ij-1]
CoefficientMat[x+1y+1] =
评论
共有 条评论