传统特征提取算法
版权声明:本⽂为博主原创⽂章,未经博主允许不得转载。 blog.csdn/baidu_36161077/article/details/81058241
传统特征提取
直接上代码吧!
from skimage.feature import greycomatrix,greycoprops
ics import accuracy_score
import pickle
from sklearn.svm import SVC
with open('/home/shen/Desktop/SVM/train_test.pickle','rb') as f:
train_features,train_labels,test_features,test_labels = pickle.load(f)
matrix = []
train_x = train_features[:,:,:,0]
test_x = test_features[:,:,:,0]
print(train_x.shape)
print(test_x.shape)
train_y = shape([-1,])
test_y = shape([-1,])
size = train_x.shape[0]
fa1 = np.zeros([size])
fb1 = np.zeros([size])
fc1 = np.zeros([size])
fd1 = np.zeros([size])
tr_1 = time.time()
for i in range(train_x.shape[0]):
glcm = greycomatrix(train_x[i], [5], [0], 256, symmetric=True, normed=True)## 计算每张图⽚的灰度共⽣矩阵
fa1[i] = props(glcm, 'contrast')# 对⽐度信息
fb1[i] = props(glcm, 'energy')#能量信息
fc1[i] = props(glcm, 'homogeneity')
fd1[i] = props(glcm, 'correlation')#相关性信息
fa1 = fa1[:,np.newaxis]
fb1 = fb1[:,np.newaxis]
fc1 = fc1[:,np.newaxis]
fd1 = fd1[:,np.newaxis]
f1 = np.concatenate([fa1,fb1,fc1,fd1],axis = 1)
model = SVC(kernel = 'rbf',C = 32)import pickle
model.fit(f1,train_y)
这个代码主要就是先计算出每⼀张图⽚的灰度共⽣矩阵,然后利⽤灰度共⽣矩阵计算每张图⽚的对⽐度信息,能量信息,相关性信息等。将提取到地这些信息拼接作为⼀张图⽚的特征信息,然后利⽤分类器对其进⾏分类。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论