%利用超像素的特征来训练分类器。一块一块地输入分类器分类 输入超像素块数来得到分类结果
clc;clear;
% no_classes = 16;
no_classes = 9;
no_train = round(1000);
load pu1200
pulabel1200=labels;
load('D:\ccpr论文程序\dataset\PaviaU.mat');
load('D:\ccpr论文程序\dataset\PaviaU_gt.mat');
load Indian_pines_gt
%%
img=paviaU;
indian_pines_gt=paviaU_gt;
indian_pines_corrected=paviaU;
%%
Resultfinal=[];
OAmax=0;
CAmean=zeros(no_classes,1);
for expi=1:1
tic
[supermatrix,sup_img,indexescell]=generatemeanmatrix(indian_pines_corrected,pulabel1200);
toc
img=supermatrix;
%选取训练集与测试集
[no_lines, no_rows, no_bands] = size(img);
img = ToVector(img);
img = img';
%每个样本选取的个数
% RandSampled_Num = round([300 300 300 300 300 300 300 300 300]);%pavia U
RandSampled_Num = round([200 200 200 200 200 200 200 200 200]);
Nonzero_map = zeros(no_lines,no_rows);
Nonzero_index = find(indian_pines_gt ~= 0);
Nonzero_map(Nonzero_index)=1;
Train_Label = [];
Train_index = [];
for ii = 1: no_classes
index_ii = find(indian_pines_gt == ii);
class_ii = ones(length(index_ii),1)* ii;
Train_Label = [Train_Label class_ii'];
Train_index = [Train_index index_ii'];
end
trainall = zeros(2,length(Train_index));
trainall(1,:) = Train_index;
trainall(2,:) = Train_Label;
indexes =[];
for i = 1: no_classes
W_Class_Index = find(Train_Label == i);
Random_num = randperm(length(W_Class_Index));
Random_Index = W_Class_Index(Random_num);
Tr_Index = Random_Index(1:RandSampled_Num(i));
indexes = [indexes Tr_Index];
end
indexes = indexes';
train_SL = trainall(:,indexes);
train_samples = img(:,train_SL(1,:))';
train_labels= train_SL(2,:)';
%选出部分分类结果作为训练样本
%1027个训练样本
% the remaining used for test
test_SL = trainall;
test_SL(:,indexes) = [];
test_samples = img(:,test_SL(1,:))';
test_labels = test_SL(2,:)';
% Normalizing Training and original img
[train_samples,M,m] = scale_func(train_samples);
[img ] = scale_func(img',M,m);
[sup_img ] = scale_func(sup_img',M,m);
%elm-------------------------------------------
train_samples=train_samples';
train_labels=train_labels';
img=img';
sup_img=sup_img';
tic
[IW,B,LW,TF,TYPE] = elmtrain(train_samples,train_labels,2050,'sig',1);%330,'sig',1);
Result=elmpredict(sup_img,IW,B,LW,TF,TYPE);%%ELM训练与测试过程
toc
temp=zeros(1,no_lines*no_rows);
for i=1:length(Result)
temp(indexescell{1,i})=Result(i);
end
Result=temp;%%将每个特征向量对应的标号赋予对应超像素
Result = Result';
%elm------------------------------------
ResultTest = Result(test_SL(1,:),:);
final=find(ResultTest==test_labels);
GroudTest = double(test_labels(:,1));
ResultTest = Result(test_SL(1,:),:);
[OA(expi),AA(expi),kappa(expi),CA(:,expi)]=confusion(GroudTest,ResultTest)
if OA(expi)>OAmax
OAmax=OA(expi);
Resultfinal=Result;%5/22
end
CAmean=CA(:,expi)+CAmean;
end
OA_mean=mean(OA)
AA_mean=mean(AA)
kappa_mean=mean(kappa)%%看十次平均值 revised 14/5/9
CAmean=CAmean/1
classmap=reshape(Resultfinal,no_lines, no_rows);
resultmap1=classmap.*Nonzero_map;
imagesc(resultmap1);
axis off;
% A=getframe;
% imshow(A.cdata)
% imwrite(A.cdata,'C:\Users\Think\Desktop\实验图像\2.jpg')
蔚蓝闲闲
- 粉丝: 4
- 资源: 1
最新资源
- 毕设和企业适用springboot区域电商平台类及物流信息平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及在线教育互动平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及智慧社区管理平台源码+论文+视频.zip
- 毕设和企业适用springboot人工智能类及企业数字资产管理平台源码+论文+视频.zip
- 毕设和企业适用springboot人工智能类及气象数据管理系统源码+论文+视频.zip
- 毕设和企业适用springboot人工智能类及企业风险监控平台源码+论文+视频.zip
- 毕设和企业适用springboot商城类及智能农业解决方案源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及VR互动平台源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及大数据存储平台源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及大数据实时处理系统源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及大数据云平台源码+论文+视频.zip
- 毕设和企业适用springboot全渠道电商平台类及电商产品推荐平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及智能云平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及自动化控制系统源码+论文+视频.zip
- 毕设和企业适用springboot全渠道电商平台类及个性化广告平台源码+论文+视频.zip
- 毕设和企业适用springboot全渠道电商平台类及酒店管理平台源码+论文+视频.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈