import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import SVC
from skimage import feature as skft
from sklearn.metrics import classification_report
def loadPicture():
train_index = 0
test_index = 0
train_data = np.zeros( (200,171,171) )
test_data = np.zeros( (160,171,171) )
train_label = np.zeros( (200) )
test_label = np.zeros( (160) )
for i in np.arange(40):
image = mpimg.imread('picture/'+str(i)+'.tiff')
data = np.zeros( (513,513) )
data[0:image.shape[0],0:image.shape[1]] = image
#切割后的图像位于数据的位置
index = 0
#将图片分割成九块
for row in np.arange(3):
for col in np.arange(3):
if index<5:
train_data[train_index,:,:] = data[171*row:171*(row+1),171*col:171*(col+1)]
train_label[train_index] = i
train_index+=1
#mpimg.imread('picture/'+str(i)+'.tiff')
arr='picture_train/'+str(i*9+index)+'.tiff'
mpimg.imsave(fname=arr,arr=data[171*row:171*(row+1),171*col:171*(col+1)])
else:
test_data[test_index,:,:] = data[171*row:171*(row+1),171*col:171*(col+1)]
test_label[test_index] = i
test_index+=1
arr='picture_test/'+str(i*9+index)+'.tiff'
mpimg.imsave(fname=arr,arr=data[171*row:171*(row+1),171*col:171*(col+1)])
index+=1
return train_data,test_data,train_label,test_label
radius = 1
n_point = radius * 8
def texture_detect():
train_hist = np.zeros( (200,256) )
test_hist = np.zeros( (160,256) )
for i in np.arange(200):
#使用LBP方法提取图像的纹理特征.
lbp=skft.local_binary_pattern(train_data[i],n_point,radius,'default')
#统计图像的直方图
max_bins = int(lbp.max() + 1)
#hist size:256
train_hist[i], _ = np.histogram(lbp, normed=True, bins=max_bins, range=(0, max_bins))
for i in np.arange(160):
lbp = skft.local_binary_pattern(test_data[i],n_point,radius,'default')
#统计图像的直方图
max_bins = int(lbp.max() + 1)
#hist size:256
test_hist[i], _ = np.histogram(lbp, normed=True, bins=max_bins, range=(0, max_bins))
return train_hist,test_hist
train_data,test_data,train_label,test_label= loadPicture()
train_hist,test_hist = texture_detect()
result=[]
maxid=0
max=0
id=0
kenellist=['linear', 'poly', 'rbf', 'sigmoid']
for kenel in kenellist :
for c in range(1,2001,100):
gama=0.1
while(gama<=1):
clf = SVC(kernel=kenel, C=c, gamma=gama)
clf.fit(train_hist,train_label)
linshi=clf.score(test_hist,test_label)
result.append([kenel,c,gama,linshi])
print(id,result[id])
if max<linshi:
max=linshi
maxid=id
gama=gama+0.1
id=id+1
print(result[maxid])
clf = SVC(kernel='linear', C=700, gamma=0.1)
clf.fit(train_hist,train_label)
test_predict=clf.predict(test_hist)
print(classification_report(test_label, test_predict))
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论












资源评论

- #标题与内容不符
- #内容缺失
- #文件乱码
- #引导二次消费
- #需要密码
- #运行出错
- #毫无价值
- #上传者态度恶劣
- #无法联系上传者
- 挪威的深林2020-04-21完全是scikit-image中复制粘贴过来的,不具有参考价值,缺少太多
- baidu_248302592019-10-30Python编写缺少文件fuckguidao2019-12-31你需要自行下载依赖的库,pip指令不会用请自行百度,远程安装太慢的话请下载国内的镜像,实在想省事就下个anaconda,人工智能和数据分析的库一应俱全
fuckguidao
- 粉丝: 13
- 资源: 7

上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
已下载
下载帮助

资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
