%% Read Data from ENVI File and Replace Wavelength Values
% Read ENVI format data into the workspace by specifying a header file that contains information about hyperspectral data. The associated ENVI binary data file must be stored in the same folder as the ENVI header file.

hcube = hypercube('paviaU.hdr');

% Display the properties of the hypercube object.

hcube

% Estimate an RGB image from the data cube by using the colorize function. Increase the contrast of the RGB image using contrast stretching. Visualize the RGB image.

rgbImg = colorize(hcube,'Method','RGB','ContrastStretching',true);
figure
imagesc(rgbImg)
title('RGB Image of Data Cube')

% Assign new center wavelength values for the hyperspectral data. The number of wavelength values must be equal to the number of bands in the hyperspectral data cube. Each wavelength value must be unique values.

minWavelength = 500;
maxWavelength = 1010;
newWavelength = minWavelength:5:maxWavelength;

% Create a new hypercube object with the new wavelength values.

newhcube = hypercube('paviaU.hdr',newWavelength);

% Plot the old and the new wavelength values. Display the wavelength range.

figure
plot(hcube.Wavelength,'o')
hold on
plot(newhcube.Wavelength,'or')
xlabel('Band Number')
ylabel('Wavelength')
str1 = ['Original wavelength range: ' num2str(min(hcube.Wavelength))  'nm to ' num2str(max(hcube.Wavelength)) 'nm'];
text(5,1075,str1)
str2 = ['New wavelength range: ' num2str(min(newhcube.Wavelength))  'nm to ' num2str(max(newhcube.Wavelength)) 'nm'];
text(5,1035,str2)
legend('Original Values','New Values','Location','SouthEast')

% Copyright 2020 The MathWorks, Inc.