如何使用 GLCM 功能定位灰度图像中的暗点?
如果我使用大于一的距离,即我尝试为更大的距离制作矩阵,我是否能够检测到大块暗像素?
您可以使用对比度、能量、同质性、相关性或相异性等特征。
这些功能的 Python 代码 -
import cv2
import numpy as np
from skimage.feature import greycomatrix, greycoprops
img = cv2.imread("spot.jpg")
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
properties = ['contrast','energy', 'homogeneity','correlation','dissimilarity']
distances = [1, 2, 3]
angles = [0, np.pi/4, np.pi/2, 3*np.pi/4]
glcm = greycomatrix(gray_image,
distances=distances,
angles=angles,
symmetric=True,
normed=True)
contrast = greycoprops(glcm,properties[0])
energy = greycoprops(glcm,properties[1])
homogeneity = greycoprops(glcm,properties[2])
correlation = greycoprops(glcm,properties[3])
dissimilarity = greycoprops(glcm,properties[4])
#.......................Display.........................
print(contrast)
print(energy)
print(homogeneity)
print(correlation)
print(dissimilarity)