clear all;%只做M的特征的识别
load AR_label
load ar_2;%可变换库
%/////////////////////////////
%修改参数区
sample=59;
cut_num=3;
R=1;
P=8;
MAPPING=getmapping(P,'u2');
%////////////////////////////
class_num = 119;
sample_num = 26;
right_num = [];
row=60;
line=60;
for test_mode = 6
for loop = 1
train_num = test_mode;%每类的训练样本是6个
train_total = train_num * class_num;%所有类得训练样本总数6*26=156
test_num = sample_num - train_num;%测试样本的个数
test_total = test_num * class_num;%所有类得测试样本总数
ar_train = zeros(row,line, train_total);%0矩阵的大小行数为每类的行*列,列为所有的训练样本的个数
ar_test = zeros(row,line, test_total);
for i = 1:class_num
kk1 = (i-1)*sample_num + label(loop, 1:train_num);
kk2 = (i-1)*train_num + 1 : i*train_num;
ar_train(:,:,kk2) = ar_2(:,:,kk1);
kk1 = (i-1)*sample_num + label(loop, train_num+1:sample_num);
kk2 = (i-1)*test_num + 1 : i*test_num;
ar_test(:,:,kk2) = ar_2(:,:,kk1);
end
end
end
for i=1:train_total
ar_train(:,:,i)=gaosi(ar_train(:,:,i));%预处理
end
for i=1:test_total
ar_test(:,:,i)=gaosi(ar_test(:,:,i));
end
ar_train_new = zeros(row/cut_num,line/cut_num, cut_num*cut_num,train_total);
ar_test_new = zeros(row/cut_num,line/cut_num, cut_num*cut_num,test_total);
ar_train_new=reshape_1(ar_train,cut_num);
ar_test_new=reshape_1(ar_test,cut_num);
train_new_q=zeros(sample,train_total*cut_num*cut_num,2);
test_new_q=zeros(sample,test_total*cut_num*cut_num,2);
for i=1:train_total
for j=1:cut_num*cut_num
[S,M,C]=clbp(ar_train_new(:,:,j,i),R,P,MAPPING,'hist');
train_new_q(:,(i-1)*cut_num*cut_num+j,1)=reshape(S,[sample,1]);
train_new_q(:,(i-1)*cut_num*cut_num+j,2)=reshape(M,[sample,1]);
end
end
for i=1:test_total
for j=1:cut_num*cut_num
[S,M,C]=clbp(ar_test_new(:,:,j,i),R,P,MAPPING,'hist');
test_new_q(:,(i-1)*cut_num*cut_num+j,1)=reshape(S,[sample,1]);
test_new_q(:,(i-1)*cut_num*cut_num+j,2)=reshape(M,[sample,1]);
end
end
% train_new_S=zeros(cut_num*cut_num*sample,train_total);
% test_new_S=zeros(cut_num*cut_num*sample,test_total);
%
% train_new_M=zeros(cut_num*cut_num*sample,train_total);
% test_new_M=zeros(cut_num*cut_num*sample,test_total);
%
% train_new=zeros(cut_num*cut_num*sample*2,train_total);
% test_new=zeros(cut_num*cut_num*sample*2,test_total);
train_new_S=reshape_2(train_new_q(:,:,1),cut_num);
test_new_S=reshape_2(test_new_q(:,:,1),cut_num);
train_new_M=reshape_2(train_new_q(:,:,2),cut_num);
test_new_M=reshape_2(test_new_q(:,:,2),cut_num);
train_new=[train_new_S;train_new_M];
test_new=[test_new_S;test_new_M];
error = [];
for i = 1:class_num
for j = 1:test_num
%i,j
kk = (i-1)*test_num + j;
res_y = test_new(:,kk);
dis = [];
for ii = 1:class_num
for jj = 1:train_num
res_x = train_new(:,(ii-1)*train_num+jj);
res = (res_y - res_x).^2;
temp = sqrt(sum(res));
dis = [dis; temp];
end
end
[value, site] = min(dis);
site_new = floor((site-1)/train_num) + 1;
if site_new ~= i
error = [error; i*test_num+j];
end
end
end
right_num = [right_num; (1.0-length(error)/(class_num*test_num))*100 ];
right_num'
- 1
- 2
- 3
前往页