【疾病分类】基于matlab SVM农作物叶子虫害识别与分类【含Matlab源码 624期】
【摘要】
一、SVM简介
支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本、非线性及高维模式识别中表现出许多特有的优势,并能够推广应用到...
一、SVM简介
支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本、非线性及高维模式识别中表现出许多特有的优势,并能够推广应用到函数拟合等其他机器学习问题中。
1 数学部分
1.1 二维空间
2 算法部分
二、部分源代码
clear all
clc
disp('正在训练农作物叶子图像模板,请稍后...');
disp(' ');
%color_Ip = xunlian();
pause(2);
load C:\Users\lenovo\Desktop\图像检索\color_Ip.mat;
disp('图像训练完成,正在进行图像识别,请稍后...');
disp(' ');
pause(2);
path = input('请输入待识别叶子图像路径:'); % 'F:\病虫害识别\图像检索\示例2中等.jpg'
A = imread(path); % 读入叶子图像
G0 = lianghua_hsv(A); % 量化hsv分量并获得颜色直方图
color_Iq = color_feature(G0); % 提取颜色特征
color_Dpq = color_match(color_Ip,color_Iq); % 颜色特征匹配
[r c] = find(min(min(color_Dpq))==color_Dpq);
A=imread('F:\病虫害识别\图像检索\1.jpg');
[M,N,O] = size(A);
[h,s,v] = rgb2hsv(A);
H = h; S = s; V = v;
h = h*360;
%将hsv空间非等间隔量化:
% h量化成16级;
% s量化成4级;
% v量化成4级;
for i = 1:M
for j = 1:N
if h(i,j)<=15||h(i,j)>345
H(i,j) = 0;
end
if h(i,j)<=25&&h(i,j)>15
H(i,j) = 1;
end
if h(i,j)<=45&&h(i,j)>25
H(i,j) = 2;
end
if h(i,j)<=55&&h(i,j)>45
H(i,j) = 3;
end
if h(i,j)<=80&&h(i,j)>55
H(i,j) = 4;
end
if h(i,j)<=108&&h(i,j)>80
H(i,j) = 5;
end
if h(i,j)<=140&&h(i,j)>108
H(i,j) = 6;
end
if h(i,j)<=165&&h(i,j)>140
H(i,j) = 7;
end
if h(i,j)<=190&&h(i,j)>165
H(i,j) = 8;
end
if h(i,j)<=220&&h(i,j)>190
H(i,j) = 9;
end
if h(i,j)<=255&&h(i,j)>220
H(i,j) = 10;
end
if h(i,j)<=275&&h(i,j)>255
H(i,j) = 11;
end
if h(i,j)<=290&&h(i,j)>275
H(i,j) = 12;
end
if h(i,j)<=316&&h(i,j)>290
H(i,j) = 13;
end
if h(i,j)<=330&&h(i,j)>316
H(i,j) = 14;
end
if h(i,j)<=345&&h(i,j)>330
H(i,j) = 15;
end
end
end
for i = 1:M
for j = 1:N
if s(i,j)<=0.15&&s(i,j)>0
S(i,j) = 1;
end
if s(i,j)<=0.4&&s(i,j)>0.15
S(i,j) = 2;
end
if s(i,j)<=0.75&&s(i,j)>0.4
S(i,j) = 3;
end
if s(i,j)<=1&&s(i,j)>0.75
S(i,j) = 4;
end
end
end
for i = 1:M
for j = 1:N
if v(i,j)<=0.15&&v(i,j)>0
V(i,j) = 1;
end
if v(i,j)<=0.4&&v(i,j)>0.15
V(i,j) = 2;
end
if v(i,j)<=0.75&&v(i,j)>0.4
V(i,j) = 3;
end
if v(i,j)<=1&&v(i,j)>0.75
V(i,j) = 4;
end
end
end
% 构建4*16二维数组存放H-S数据
Hist = zeros(16,4);
for i = 1:M
for j = 1:N
for k = 1:16
for l = 1:4
if l==S(i,j)&& k==H(i,j)+1
Hist(k,l) = Hist(k,l)+1;
end
end
end
end
end
for k = 1:16
for l =1:4
His((k-1)*4+l) = Hist(k,l);%转化为一维数组
end
end
His = His/sum(His)*1000;
% 手工绘制彩色图像直方图
% hist_h
m=0;
for j = 1:300
if rem(j,16)==1 && m<16
for k = 0:15
for i = 1:200
hist_h(i,j+k) = m;
end
end
m = m+1;
end
end
% hist_s
m=0;
for j = 1:300
if rem(j,4) == 1 && m<64
n = rem(m,4);
for k = 0:3
for i =1:200
hist_s(i,j+k) = n+1;
end
end
m = m+1;
end
end
% hist_v
for j = 1:256
for i = 1:200
hist_v(i,j) = 0.98;
end
end
% 把His赋值给hist_v
for k = 1:64
for j = 1:256
if floor((j-1)/4) == k
for i = 1:200
if i<200-His(k+1)%i>His(k+1)%
hist_v(i,j) = 0;
end
end
end
end
end
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/115190641
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)