├── .gitattributes ├── GRSL 2017.pdf ├── ReadMe.txt ├── data ├── Indian_pines_corrected.mat ├── Indian_pines_gt.mat ├── Indian_pines_randp.mat ├── PaviaU_randp.mat └── Salinas_randp.mat ├── demo_JSaCR_test.m ├── randpTest.m └── utilities ├── JSaCR_Classification.m ├── confusion_matrix_wei.m ├── randpGen.m ├── randpTest.m └── samplesdivide.m /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /GRSL 2017.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junjun-jiang/JSaCR/0701ca91f40bcb5edc7d2dd95697772c05c3388c/GRSL 2017.pdf -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | *** The code is for the work, if you find it is useful, please cite our work: 2 | 3 | [1] J. Jiang, C. Chen, Y. Yu, X. Jiang, and J. Ma, "Spatial-Aware Collaborative Representation for Hyperspectral Remote Sensing Image Classification," IEEE Geoscience and Remote Sensing Letters, vol. 14, no. 3, pp. 404-408, 2017. 4 | 5 | *** To generate the file of ***_randp.mat for other database, you can use the randpTest.m to generate. 6 | 7 | If you need another two datasets (PaviaU and Salinas), please feel free to contact me. Or you can download them from http://www.ehu.eus/ccwintco/index.php/Hyperspectral_Remote_Sensing_Scenes 8 | 9 | PaviaU: http://www.ehu.eus/ccwintco/uploads/e/ee/PaviaU.mat, http://www.ehu.eus/ccwintco/uploads/5/50/PaviaU_gt.mat 10 | 11 | Salinas: http://www.ehu.eus/ccwintco/uploads/a/a3/Salinas_corrected.mat, http://www.ehu.eus/ccwintco/uploads/f/fa/Salinas_gt.mat 12 | -------------------------------------------------------------------------------- /data/Indian_pines_corrected.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junjun-jiang/JSaCR/0701ca91f40bcb5edc7d2dd95697772c05c3388c/data/Indian_pines_corrected.mat -------------------------------------------------------------------------------- /data/Indian_pines_gt.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junjun-jiang/JSaCR/0701ca91f40bcb5edc7d2dd95697772c05c3388c/data/Indian_pines_gt.mat -------------------------------------------------------------------------------- /data/Indian_pines_randp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junjun-jiang/JSaCR/0701ca91f40bcb5edc7d2dd95697772c05c3388c/data/Indian_pines_randp.mat -------------------------------------------------------------------------------- /data/PaviaU_randp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junjun-jiang/JSaCR/0701ca91f40bcb5edc7d2dd95697772c05c3388c/data/PaviaU_randp.mat -------------------------------------------------------------------------------- /data/Salinas_randp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junjun-jiang/JSaCR/0701ca91f40bcb5edc7d2dd95697772c05c3388c/data/Salinas_randp.mat -------------------------------------------------------------------------------- /demo_JSaCR_test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junjun-jiang/JSaCR/0701ca91f40bcb5edc7d2dd95697772c05c3388c/demo_JSaCR_test.m -------------------------------------------------------------------------------- /randpTest.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | database = 'KSC'; 6 | 7 | load([database '_gt.mat']); 8 | 9 | gth = KSC_gt; 10 | 11 | IterNum = 10; 12 | randp = randpGen(gth,IterNum); 13 | save([database '_gt_randp.mat']); 14 | 15 | -------------------------------------------------------------------------------- /utilities/JSaCR_Classification.m: -------------------------------------------------------------------------------- 1 | function class = JSaCR_Classification(DataTrains, CTrain, DataTests, lambda, c, gamma) 2 | 3 | DataTrain = DataTrains(:,3:end); 4 | DataTest = DataTests(:,3:end); 5 | 6 | DDT = DataTrain*DataTrain'; 7 | 8 | numClass = length(CTrain); 9 | [m Nt]= size(DataTest); 10 | for j = 1: m 11 | if mod(j,round(m/20))==0 12 | fprintf('*...'); 13 | end 14 | 15 | xy = DataTests(j, 1:2); 16 | XY = DataTrains(:, 1:2); 17 | norms = sum((abs(XY' - repmat(xy', [1 size(XY,1)]))).^c); 18 | norms = norms./max(norms); 19 | D = diag(gamma.*norms); 20 | 21 | Y = DataTest(j, :); % 1 x dim 22 | norms = sum((DataTrain' - repmat(Y', [1 size(DataTrain,1)])).^2); 23 | % norms = ones(size(DataTrain,1), 1); 24 | G = diag(lambda.*norms); 25 | weights = (DDT + G + D)\(DataTrain*Y'); 26 | 27 | a = 0; 28 | for i = 1: numClass 29 | % Obtain Multihypothesis from training data 30 | HX = DataTrain((a+1): (CTrain(i)+a), :); % sam x dim 31 | HW = weights((a+1): (CTrain(i)+a)); 32 | a = CTrain(i) + a; 33 | Y_hat = HW'*HX; 34 | 35 | Dist_Y(j, i) = norm(Y - Y_hat); 36 | end 37 | Dist_Y(j, :) = Dist_Y(j, :)./sum(Dist_Y(j, :)); 38 | end 39 | [~, class] = min(Dist_Y'); 40 | -------------------------------------------------------------------------------- /utilities/confusion_matrix_wei.m: -------------------------------------------------------------------------------- 1 | function [confusion, accuracy, TPR, FPR] = confusion_matrix_wei(class, c) 2 | % 3 | % class is the result of test data after classification 4 | % (1 x n) 5 | % 6 | % c is the label for testing data 7 | % (1 x len_c) 8 | % 9 | % 10 | 11 | class = class.'; 12 | c = c.'; 13 | 14 | n = length(class); 15 | c_len = length(c); 16 | 17 | if n ~= sum(c) 18 | disp('WRANING: wrong inputting!'); 19 | return; 20 | end 21 | 22 | 23 | % confusion matrix 24 | confusion = zeros(c_len, c_len); 25 | a = 0; 26 | for i = 1: c_len 27 | for j = (a + 1): (a + c(i)) 28 | confusion(i, class(j)) = confusion(i, class(j)) + 1; 29 | end 30 | a = a + c(i); 31 | end 32 | 33 | 34 | % True_positive_rate + False_positive_rate + accuracy 35 | TPR = zeros(1, c_len); 36 | FPR = zeros(1, c_len); 37 | for i = 1: c_len 38 | FPR(i) = confusion(i, i)/sum(confusion(:, i)); 39 | TPR(i) = confusion(i, i)/sum(confusion(i, :)); 40 | end 41 | accuracy = sum(diag(confusion))/sum(c); 42 | -------------------------------------------------------------------------------- /utilities/randpGen.m: -------------------------------------------------------------------------------- 1 | 2 | function randp = randpGen(gth,IterNum) 3 | randp = cell(1,IterNum); 4 | for i=1:IterNum 5 | for c=1:max(gth(:)) 6 | randp{1,i}{1,c} = randperm(length(find(gth==c))); 7 | end 8 | end -------------------------------------------------------------------------------- /utilities/randpTest.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | database = 'KSC'; 6 | 7 | load([database '_gt.mat']); 8 | 9 | gth = KSC_gt; 10 | 11 | IterNum = 10; 12 | randp = randpGen(gth,IterNum); 13 | save([database '_gt_randp.mat']); 14 | 15 | -------------------------------------------------------------------------------- /utilities/samplesdivide.m: -------------------------------------------------------------------------------- 1 | function [DataTest DataTrain CTest CTrain Loc_test] = samplesdivide(indian_pines_corrected,indian_pines_gt,train,randpp); 2 | 3 | CTrain = []; 4 | CTest = []; 5 | DataTest = []; 6 | DataTrain = []; 7 | 8 | [m n p] = size(indian_pines_corrected); 9 | indian_pines_map = uint8(zeros(m,n)); 10 | data_col = reshape(indian_pines_corrected,m*n,p); 11 | [mm nn] = ind2sub([m n],1:m*n); 12 | data_col = [mm' nn' data_col]; 13 | 14 | for i = 1:max(indian_pines_gt(:)) 15 | ci = length(find(indian_pines_gt==i)); 16 | [v]=find(indian_pines_gt==i); 17 | datai = data_col(find(indian_pines_gt==i),:); 18 | if train>1 19 | cTrain = round(train); 20 | else 21 | cTrain = round(train*ci); 22 | end 23 | cTest = ci-cTrain; 24 | CTrain = [CTrain cTrain]; 25 | CTest = [CTest cTest]; 26 | index = randpp{i}; 27 | DataTest = [DataTest; datai(index(1:cTest),:)]; 28 | DataTrain = [DataTrain; datai(index(cTest+1:cTest+cTrain),:)]; 29 | end 30 | 31 | Normalize = max(max(DataTrain(:,3:end))); 32 | DataTrain(:,3:end) = DataTrain(:,3:end)./Normalize; 33 | DataTest(:,3:end) = DataTest(:,3:end)./Normalize; 34 | 35 | --------------------------------------------------------------------------------