-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPPI.m
More file actions
67 lines (56 loc) · 1.9 KB
/
Copy pathPPI.m
File metadata and controls
67 lines (56 loc) · 1.9 KB
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
60
61
62
63
64
65
66
67
hcube = imhypercube("PaviaU.hdr")
numEndmembers = countEndmembersHFC(hcube,PFA=10^-7);
datacube = gather(hcube);
endmembers_ppi = ppi(datacube,numEndmembers);
figure
plot(endmembers_ppi)
xlabel("Band Number")
ylabel("Pixel Values")
title({"Endmembers Spectra","Number of Endmembers = "+num2str(numEndmembers)});
ylim([0 9000])
figure
datacube = gather(hcube)
abundanceMap = estimateAbundanceLS(datacube,endmembers_ppi,Method="fcls");
montage(abundanceMap(:,:,1:numEndmembers),Size=[1 numEndmembers],BorderSize=[20 20])
colormap default
colorbar
title("PPI Em 1 | Em 2 | Em 3 | Em 4 | Em 5 | Em 6 | Em 7 | Em 8 ",FontSize=14)
datacube = gather(hcube);
score = zeros(size(datacube,1),size(datacube,2),numEndmembers);
for i = 1:numEndmembers
score(:,:,i) = sam(hcube,endmembers_ppi(:,i));
end
[~,matchingIndx] = min(score,[],3);
rgbImg = colorize(hcube,Method="rgb");
figure(Position=[0 0 1100 500])
subplot(Position=[0 0.15 0.4 0.8])
imagesc(rgbImg)
axis off
title("RGB Image of Hyperspectral Data")
subplot(Position=[0.45 0.15 0.4 0.8])
imagesc(matchingIndx)
axis off
title("Indices of Matching Endmembers")
colorbar
score = zeros(1,numEndmembers-1);
refSpectrum = endmembers_ppi(:,numEndmembers);
for i = 2:numEndmembers
testSpectrum = endmembers_ppi(:,i);
score(i-1) = sam(testSpectrum,refSpectrum);
end
[minval,minidx] = min(score);
maxMatch = endmembers_ppi(:,minidx);
[maxval,maxidx] = max(score);
minMatch = endmembers_ppi(:,maxidx);
figure
plot(refSpectrum)
hold on
plot(maxMatch,"k")
plot(minMatch,"r")
xlabel("Band Number")
ylabel("Data Values")
legend("Reference spectrum","Minimum match test spectrum","Maximum match test spectrum", ...
Location="southoutside")
title("Similarity Between Spectra")
annotation("textarrow",[0.25 0.25],[0.4 0.5],String="Max score: "+maxval)
annotation("textarrow",[0.6 0.55],[0.6 0.45],String="Min score: "+minval)