资源简介
题目是将图片库中的纹理图片裁剪成九份,其中五份做训练集,四份做测试集,先提取图片LBP特征 ,最后用svm支持向量机进行学习,在预测测试集里的图片是哪一类纹理。
正常情况下是需要调参的,即调整SVM的参数,但图省事只整了个循环,正常应该手动调参的。

代码片段和文件信息
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( (200171171) )
test_data = np.zeros( (160171171) )
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( (513513) )
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=arrarr=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=arrarr=data[171*row:171*(row+1)171*col:171*(col+1)])
index+=1
return train_datatest_datatrain_labeltest_label
radius = 1
n_point = radius * 8
def texture_detect():
train_hist = np.zeros( (200256) )
test_hist = np.zeros( (160256) )
for i in np.arange(200):
#使用LBP方法提取图像的纹理特征.
lbp=skft.local_binary_pattern(train_data[i]n_pointradius‘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_pointradius‘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_histtest_hist
train_datatest_datatrain_labeltest_label= loadPicture()
train_histtest_hist = texture_detect()
result=[]
maxid=0
max=0
id=0
kenellist=[‘linear‘ ‘poly‘ ‘rbf‘ ‘sigmoid‘]
for kenel in kenellist :
for c in range(12001100):
gama=0.1
while(gama<=1):
clf = SVC(kernel=kenel C=c gamma=gama)
clf.fit(train_histtrain_label)
linshi=clf.score(test_histtest_label)
result.append([kenelcgamalinshi])
print(idresult[id])
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-06-27 18:33 test\
目录 0 2019-06-27 18:33 test\picture\
文件 264554 2005-12-07 20:48 test\picture\0.tiff
文件 264126 2005-12-07 20:39 test\picture\1.tiff
文件 263466 2005-12-07 20:42 test\picture\10.tiff
文件 264724 2005-12-07 20:42 test\picture\11.tiff
文件 262548 2005-12-07 20:42 test\picture\12.tiff
文件 264694 2005-12-07 20:43 test\picture\13.tiff
文件 262128 2005-12-07 20:43 test\picture\14.tiff
文件 264724 2005-12-07 20:43 test\picture\15.tiff
文件 264676 2005-12-07 20:43 test\picture\16.tiff
文件 264666 2005-12-07 20:43 test\picture\17.tiff
文件 264654 2005-12-07 20:44 test\picture\18.tiff
文件 264714 2005-12-07 20:44 test\picture\19.tiff
文件 264506 2005-12-07 20:39 test\picture\2.tiff
文件 264646 2005-12-07 20:44 test\picture\20.tiff
文件 262166 2005-12-07 20:44 test\picture\21.tiff
文件 261812 2005-12-07 20:44 test\picture\22.tiff
文件 264136 2005-12-07 20:45 test\picture\23.tiff
文件 264694 2005-12-07 20:45 test\picture\24.tiff
文件 264554 2005-12-07 20:45 test\picture\25.tiff
文件 264514 2005-12-07 20:45 test\picture\26.tiff
文件 264154 2005-12-07 20:45 test\picture\27.tiff
文件 264674 2005-12-07 20:46 test\picture\28.tiff
文件 264554 2005-12-07 20:46 test\picture\29.tiff
文件 264742 2005-12-07 20:40 test\picture\3.tiff
文件 264734 2005-12-07 20:46 test\picture\30.tiff
文件 264752 2005-12-07 20:46 test\picture\31.tiff
文件 263156 2005-12-07 20:46 test\picture\32.tiff
文件 264730 2005-12-07 20:47 test\picture\33.tiff
文件 263698 2005-12-07 20:47 test\picture\34.tiff
............此处省略12个文件信息
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论