gpt4 book ai didi

python - 从 GLCM 中提取 Haralick 特征。为什么我会为每个功能获取多个值?

转载 作者:行者123 更新时间:2023-12-05 06:32:26 25 4
gpt4 key购买 nike

我看过this昨天的纸在本文中,这些特征被视为对比度局部同质性能量,它们都是单个值(据我所知)但根据到 skimage 函数 greycomatrix,传递给它们的参数是 distancesangles(可以是多个)。

这是我的代码:

import numpy as np
import cv2
from skimage.feature import greycomatrix, greycoprops
from skimage import io, color, img_as_ubyte

img = cv2.imread('Grape___Black_rot28.JPG')
gray_image = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

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)

properties = ['contrast', 'energy', 'homogeneity', 'correlation', 'dissimilarity']
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])

让我感到困惑的是,如果我生成一个对比度属性的 glcm,它将是 3x4 大小,但根据论文,它是一个单一值,即使我将所有属性的所有 3x4 值都视为一个特征,我敢打赌对svm模型会有过拟合的问题。

最佳答案

来自 graycoproprops文档:

Returns:     results : 2-D ndarray

                      2-dimensional array. results[d, a] is the property ‘prop’ for the d’th
                      distance and the a’th angle.

您的代码为每个距离-角度组合生成一个特征值:

In [5]: len(distances)
Out[5]: 3

In [6]: len(angles)
Out[6]: 4

In [7]: contrast.shape
Out[7]: (3, 4)

实现旋转不变性的常见做法是沿角度 轴平均特征值。通过这样做,您将获得与距离一样多的特征值:

In [11]: contrast = greycoprops(glcm, properties[0]).mean(axis=1)

In [12]: contrast.shape
Out[12]: (3,)

关于python - 从 GLCM 中提取 Haralick 特征。为什么我会为每个功能获取多个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51337067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com