%% Reconstruct Data From Principal Component Coefficients
% Read a hyperspectral data into the workspace.

hcube = hypercube('indian_pines.dat');

% Extract 10 principal component bands and the transformation coefficients using the principal component analysis method.

[pcDataCube,coeff] = hyperpca(hcube,10);

% Reconstruct the original data from 10 principal component bands.

reconstructedData = inverseProjection(pcDataCube,coeff);

% Display the first 10 spectral bands in input data cube.

figure
montage(hcube.DataCube(:,:,1:10),'BorderSize',[10 10],'Size',[2 5],'DisplayRange',[]);
title('Original Data Cube')

% Display the first 10 spectral bands in the reconstructed data cube.

figure
montage(reconstructedData(:,:,1:10),'BorderSize',[10 10],'Size',[2 5],'DisplayRange',[]);
title('Reconstructed Data Cube')

% Copyright 2020 The MathWorks, Inc.