%% Extract Endmembers Using Fast Iterative Pixel Purity Index
% Read a hyperspectral data into the workspace.

hcube = hypercube('paviaU.hdr');

% Find the number of spectrally distinct endmembers present in the hyperspectral data cube by using countEndmembersHFC function.

numEndmembers = countEndmembersHFC(hcube,'PFA',10^-7);

% Compute the endmembers using the fast iterative pixel purity index (FIPPI) method. By default, the fippi function uses maximum noise fraction (MNF) transform for preprocessing.

endmembers = fippi(hcube.DataCube,numEndmembers);

% Plot the endmembers of the hyperspectral data.

figure
plot(endmembers)
xlabel('Band Number')
ylabel('Pixel Values')
ylim([0 9000])
title({'Endmembers Spectra',['Number of Endmembers = ' num2str(numEndmembers)]});

% Copyright 2020 The MathWorks, Inc.