-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.m
65 lines (48 loc) · 1.21 KB
/
main.m
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
close all
clear
clc
%% load data
load PaviaU;
img_src = paviaU;
clear paviaU;
load PaviaU_gt;
img_gt = paviaU_gt(:);
clear paviaU_gt;
[W, H, L]=size(img_src);
img_src = double(img_src);
img_src = reshape(img_src, W * H, L);
%% band selection
tic
K = 6; % the number of selected bands K
for i = 1 : L
img(:, i) = img_src(:,i) / max(max(img_src(:,i)));
end
D = get_D(img);
P = ASPS(D, L, K);
%H = Entrop(img); %choose information entropy to select band in each subcube
N = NoiseLevel(img, W, H, L);
for i = 1 : K - 1
if i == 1
index = 1;
else
index = P(i) + 1;
end
%[~, b] = max(H(index : P(i+1)));
[~, b] = min(N(index : P(i + 1)));
Y(i )= b + index - 1;
end
toc
Y % that is bandSet
%% evaluation
newData = img_src(:, Y)';
trnPer = 0.1; % 10% samples from each class based on selected bands are selected
clsCnt = length(unique(img_gt)) - 1;
[trnData, trnLab, tstData, tstLab] = TrainTest(newData', img_gt, trnPer, clsCnt);
tstNum = zeros(1, clsCnt);
for i = 1 : clsCnt
index = find(tstLab == i);
tstNum(i) = length(index);
end
k = 5; % the parameter of KNN
preLab = KNN(trnData, trnLab, tstData, tstLab, k);
acc = accuracy(tstLab, preLab, clsCnt, tstNum)