• 大小: 6.28MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-03
  • 语言: Matlab
  • 标签: 高光谱  分类  matlab  

资源简介

首先利用PCA进行降维,并利用SVM对高光谱数据进行分类,数据采用印第安纳农场数据,训练样本比例可调,设计了一个GUI

资源截图

代码片段和文件信息

load Indian_pines_corrected.mat;
load Indian_pines_gt.mat;  %读图

[xyz]=size(indian_pines_corrected);
data1=indian_pines_corrected(1:x1:y50);
data2=indian_pines_corrected(1:x1:y100);
data3=indian_pines_corrected(1:x1:y160);
dataout(::1)=imadjust(uint16(data1));
dataout(::2)=imadjust(uint16(data2));
dataout(::3)=imadjust(uint16(data3));

figure;
imshow(dataout);
title(‘合成的假彩色显示‘);

[lwb] = size(indian_pines_corrected);%l(length)图像长度,w(width)图像宽度,b(band)波段数 
c = max(max(indian_pines_gt));%c(category)标准分类结果中的类别数
colormap_indian_pines = zeros(c3);
colormap_indian_pines(1:) = [0.74510.74510.7451];%灰色
colormap_indian_pines(2:) = [010];%绿色
colormap_indian_pines(3:) = [001];%蓝色
colormap_indian_pines(4:) = [00.54510];%深绿色
colormap_indian_pines(5:) = [10.647060];%橙色
colormap_indian_pines(6:) = [0.80390.521570.24706];%棕色
colormap_indian_pines(7:) = [0.62750.125490.94118];%紫色
colormap_indian_pines(8:) = [100];%红色
colormap_indian_pines(9:) = [110];%黄色
colormap_indian_pines(10:) = [10.89410.76863];%橘黄色
colormap_indian_pines(11:) = [0.94111];%天蓝色
colormap_indian_pines(12:) = [011];%青色
colormap_indian_pines(13:) = [10.8430];%金色
colormap_indian_pines(14:) = [101];%洋红
colormap_indian_pines(15:) = [000.5019];%海军蓝
colormap_indian_pines(16:) = [110.87843];%浅黄色
pavia_truthmap = zeros(lw3);%用于显示的帕维亚大学标准分类结果
for k = 1:c
    for i = 1:l
        for j = 1:w
            if indian_pines_gt(ij) == k
                pavia_truthmap(ij:) = colormap_indian_pines(k:);         
            end
        end
    end
end
figure;
imshow(pavia_truthmap[]);title(‘真值图显示‘);

indian_pines_corrected = myPCA(indian_pines_corrected);      %PCA降维
indian_pines_corrected = reshape(indian_pines_corrected145*145200);    %将高光谱按波段排列
[indian_pines_corrected maxV minV] = scale(indian_pines_corrected 0 1);  %归一化处理,以便后续分类
indian_pines_gt = indian_pines_gt(:);      %数据按列排
[trainindexvalidindextestindex~] = SampleSelect(indian_pines_gt0.1); % 选择10%的样本作训练

testindex = [testindex;validindex];     % 其余的样本作测试
TrainSamp = indian_pines_corrected(trainindex:)‘;%根据训练样本的标号找出训练样本
TestSamp = indian_pines_corrected(testindex:)‘;  %根据测试样本的标号找出测试样本
TrainLabel = indian_pines_gt(trainindex);    %训练样本标签
TestLabel = indian_pines_gt(testindex);     %测试样本标签

[bestcbestg] = GetcgCrossvalidate(TrainSampTrainLabel); %找到最优的SVM参数c和g
model = svmtrain(TrainLabelTrainSamp‘[‘-c ‘num2str(bestc)‘-g‘num2str(bestg)‘ -b 1 -q‘]);   %训练SVM分类器
disp(‘> SVM model trained‘);
[Labels~~] = svmpredict(TestLabelTestSamp‘model‘-b 1‘);        %SVM分类      svmpredict和svmtrain都是MATLAB自带的函数
Result = Confusmat(TestLabel Labels);          %计算混淆矩阵、总体分类精度、Kappa系数、生产者精度、用户精度

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2997  2019-05-15 09:01  高光谱\classification.m

     文件       1750  2019-05-14 09:02  高光谱\Confusmat.m

     文件       1125  2019-05-13 16:09  高光谱\fenlei.m

     文件       1517  2017-06-20 08:21  高光谱\GetcgCrossvalidate.m

     文件      36806  2019-05-13 23:24  高光谱\HSIclassificationGUI.fig

     文件      11356  2019-05-15 08:28  高光谱\HSIclassificationGUI.m

     文件       1701  2019-05-13 22:04  高光谱\HSIdisplay1.m

     文件    5953527  2019-05-13 15:52  高光谱\Indian_pines_corrected.mat

     文件       1125  2019-05-13 15:52  高光谱\Indian_pines_gt.mat

     文件        556  2019-05-13 16:11  高光谱\jingdujiance.m

     文件       1497  2014-04-01 06:57  高光谱\libsvm-3.18\COPYRIGHT

     文件      78971  2014-04-01 06:57  高光谱\libsvm-3.18\FAQ.html

     文件      27670  2014-04-01 06:57  高光谱\libsvm-3.18\heart_scale

     文件      63803  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm\svm.java

     文件      63095  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm\svm.m4

     文件        868  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm\svm_model.java

     文件        115  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm\svm_node.java

     文件       1288  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm\svm_parameter.java

     文件         87  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm\svm_print_interface.java

     文件        136  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm\svm_problem.java

     文件      51916  2014-04-01 06:57  高光谱\libsvm-3.18\java\libsvm.jar

     文件        624  2014-04-01 06:57  高光谱\libsvm-3.18\java\Makefile

     文件       4950  2014-04-01 06:57  高光谱\libsvm-3.18\java\svm_predict.java

     文件       8944  2014-04-01 06:57  高光谱\libsvm-3.18\java\svm_scale.java

     文件      12269  2014-04-01 06:57  高光谱\libsvm-3.18\java\svm_toy.java

     文件       8355  2014-04-01 06:57  高光谱\libsvm-3.18\java\svm_train.java

     文件         81  2014-04-01 06:57  高光谱\libsvm-3.18\java\test_applet.html

     文件        732  2014-04-01 06:57  高光谱\libsvm-3.18\Makefile

     文件       1084  2014-04-01 06:57  高光谱\libsvm-3.18\Makefile.win

     文件       4069  2014-04-01 06:57  高光谱\libsvm-3.18\matlab\libsvmread.c

............此处省略65个文件信息

评论

共有 条评论