test_index += 1
index += 1
return train_data, test_data, train_label, test_label
#纹理检测
def texture\_detect(self):
train_data, test_data, train_label, test_label = self.loadPicture()
n_point = self.n_point
radius = self.radius
train_hist = np.zeros((10, 256))
test_hist = np.zeros((8, 256))
#LBP特征提取
for i in np.arange(10):
# 使用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(8):
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
#训练分类器 SVM支持向量机分类
def classifer(self):
train_data, test_data, train_label, test_label = self.loadPicture()
train_hist, test_hist = self.texture_detect()
#构建SVM支持向量机
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
model= OneVsRestClassifier(svr_rbf, -1)
model.fit(train_hist, train_label)
image=cv2.imread('dataset1/image.png',cv2.IMREAD_GRAYSCALE)
image=cv2.resize(image,(588,294))
img_ku=skft.local_binary_pattern(image,8,1,'default')
thresh=cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
#对图像进行识别分类
img_data=np.zeros((1,98,98))
data=np.zeros((294,588))
data[0:image.shape[0],0:image.shape[1]]=image
img = Image.open('texture.png')
draw = ImageDraw.Draw(img)
# 设置字体和大小
myfont = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=180)
# 设置字体颜色
fillcolor = "#008B8B"
# 读取图片的size,也就是宽度和高度
width, height = img.size
#通过行列将图像分为九块
for row in np.arange(3):
for col in np.arange(6):
img_data[0,:,:]=data[98\*row:98\*(row+1),98\*col:98\*(col+1)]
lbp= skft.local_binary_pattern(img_data[0], 8, 1, 'default')
max_bins=int(lbp.max()+1)
img_hist, _ = np.histogram(lbp, normed=True, bins=max_bins, range=(0, max_bins))
predict=model.predict(img_hist.reshape(1,-1))
if(predict==0):
draw.text((width/6, height/6), '0', font=myfont, fill=fillcolor)
data[98\*row:98\*(row+1),98\*col:98\*(col+1)]=0
else:
draw.text((2\*width /3, height/6), '1', font=myfont, fill=fillcolor)
data[98\*row:98\*(row+1),98\*col:98\*(col+1)]=255
plt.subplot(211)
plt.imshow(img_ku,'gray')
#plt.subplot(312)
#plt.imshow(thresh,'gray')
plt.subplot(212)
plt.imshow(img)
plt.show()
if name == ‘__main__’:
test = Texture()
# 计算分类准确度部分
accuracy = test.classifer()
#print(‘Final Accuracy = ‘+str(accuracy)+’%’)
| 3️⃣实验结果 |
| --- |
上面一张图是结果LBP算子特征提取后的图片,下面一张图使用SVM进行纹理分类后得到的结果,与预测的左上图纹理相同标为0,与右上图相同标为1。
![在这里插入图片描述](https://img-blog.csdnimg.cn/0cfdf80e7b4248989cec93c20a838561.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5oyv5Y2OT1BQTw==,size_20,color_FFFFFF,t_70,g_se,x_16)
| [⭐实验源码+报告⭐]( ) |
| --- |
>
> 在Linux的各大发行版中,Ubuntu及其衍生版本一直享有对用户友好的美誉。Ubuntu是一个开源操作系统,它的系统和软件可以在官方网站(http://cn.ubuntu.com)免费下载,并且提供了详细的安装方式说明。
>
**一、Python所有方向的学习路线**
Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。
![img](https://img-blog.csdnimg.cn/1d40facda2b84990b8e1743f5487d455.png)
![img](https://img-blog.csdnimg.cn/0fc11d4a31bd431dbf124f67f1749046.png)
**二、Python必备开发工具**
工具都帮大家整理好了,安装就可直接上手!![img](https://img-blog.csdnimg.cn/ff266f529c6a46c4bc28e5f895dec647.gif#pic_center)
**三、最新Python学习笔记**
当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。
![img](https://img-blog.csdnimg.cn/6d414e9f494742db8bcc3fa312200539.png)
**四、Python视频合集**
观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。
![img](https://img-blog.csdnimg.cn/a806d9b941c645858c61d161aec43789.png)
**五、实战案例**
纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。![img](https://img-blog.csdnimg.cn/a353983317b14d3c8856824a0d6186c1.png)
**六、面试宝典**
![在这里插入图片描述](https://img-blog.csdnimg.cn/97c454a3e5b4439b8600b50011cc8fe4.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/111f5462e7df433b981dc2430bb9ad39.png)
###### **简历模板**![在这里插入图片描述](https://img-blog.csdnimg.cn/646863996ac44da8af500c049bb72fbd.png#pic_center)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化学习资料的朋友,可以戳这里无偿获取](https://bbs.csdn.net/topics/618317507)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**