-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFRFdemo.m
58 lines (55 loc) · 1.73 KB
/
IFRFdemo.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
clc,clear
addpath('./libsvm/');
addpath('./drtoolbox/');
no_classes = 16;
no_train = round(1024);
%%%%%
% load the ground truth and the hyperspectral image
path='.\Dataset\';
inputs = 'IndiaP';
location = [path,inputs];
load (location);
%%% size of image
[no_lines, no_rows, no_bands] = size(img);
GroundT=GroundT';
%%% construct traing and test dataset
indexes=train_test_random_new(GroundT(2,:),fix(no_train/no_classes),no_train);
%%% image fusion
img2=average_fusion(img,20);
%%% normalization
no_bands=size(img2,3);
fimg=reshape(img2,[no_lines*no_rows no_bands]);
[fimg] = scale_new(fimg);
fimg=reshape(fimg,[no_lines no_rows no_bands]);
%%% IFRF feature construction
fimg=spatial_feature(fimg,200,0.3);
%%% SVM classification
fimg = ToVector(fimg);
fimg = fimg';
fimg=double(fimg);
%%%
train_SL = GroundT(:,indexes);
train_samples = fimg(:,train_SL(1,:))';
train_labels= train_SL(2,:)';
%
test_SL = GroundT;
test_SL(:,indexes) = [];
test_samples = fimg(:,test_SL(1,:))';
test_labels = test_SL(2,:)';
% Normalizing Training and original img
[train_samples,M,m] = scale_func(train_samples);
[fimg ] = scale_func(fimg',M,m);
% Selecting the paramter for SVM
[Ccv Gcv cv cv_t]=cross_validation_svm(train_labels,train_samples);
% Training using a Gaussian RBF kernel
parameter=sprintf('-c %f -g %f -m 500 -t 2 -q',Ccv,Gcv);
model=svmtrain(train_labels,train_samples,parameter);
% Testing
Result = svmpredict(ones(no_lines*no_rows,1),fimg,model);
% Evaluation
GroudTest = double(test_labels(:,1));
ResultTest = Result(test_SL(1,:),:);
[OA,AA,kappa,CA]=confusion(GroudTest,ResultTest)
Result = reshape(Result,no_lines,no_rows);
VClassMap=label2color(Result,'india');
figure,imshow(VClassMap);