%% demo LORSAL_MLL_AS: Hyperspectral segmentation  for the AVIRIS Indian
%% Pines dataset 

close all
clear all
clc

% load image
load imgreal;

img = ToVector(img);
img = img';

% discard noisy bands  
img([104:108 150:163 220],:) =[];

%% 16 classes
% % % % load traing set
% % % load AVIRIS_Indiana_16class
% % % trainall = trainall';
% % % % randomly select the training set
% % % indexes=train_test_random_new(trainall(2,:),20,500);  
% % % train = trainall(:,indexes);
% % % % the remaining samples used as the  test set
% % % test = trainall;
% % % test(:,indexes)=[];
% % % 
% % % % load the ground truth image
% % % open('AVIRISindian16classtrue.fig')
% % % mycmap = get(figure(1),'Colormap');
% end

%% 9 classes

load alltraining;
trainall = alltrain(1:2,:); 
indexes=train_test_random_new(trainall(2,:),20,200);
train = trainall(:,indexes);
load teste;
test = teste(:,1:2);
test = test';
palete=[ 0 1 2 0 3 4 0 5 0 6 7 8 0 9];
test(2,:) = palete(test(2,:));
clear teste alltrain



open('AVIRISindiantrue.fig')
mycmap = get(figure(1),'Colormap');

% arrange the image struct
img = struct('im',img,'size',[145 145],'mycolormap',mycmap);

% arrange the AL_sampling struct
AL_method = 'RS';  % active learning method, 
                   %    RS  -- random selection
                   %    MI  -- mutual information
                   %    BT  -- breaking ties
                   %    MBT -- mordified breaking ties
candidate = trainall;  % candidate set
U = 500;           %  total size of actively selected samples
u = 50;            % new samples per iteration
AL_sampling = struct('AL_method',AL_method,'candidate',candidate,'U',U,'u',u);

% implement the supervised segmentation algorithm by using LORSAL and MLL
% spatial prior with active learnign
[class_results,seg_results] = LORSAL_MLL_AS(img,train,test,[],[],[],AL_sampling);
fprintf(' \n');
fprintf('Classification results:   \n');
disp(class_results);
fprintf(' \n');
fprintf('Segmentation results:   \n');
disp(seg_results);
