MATLAB interface

16 Nov 2017

Contents

With our database, we provide a set of functions for opening and manipulating the hyperspectral images in MATLAB. These functions can be downloaded as a zipped file:

Naturally, make sure that all of the documents within the Zip file are copied to a folder on your MATLAB path. For more information about the MATLAB path, please see here.

An example session

If you plan on using our PCA reduced hyperspectral images, then a usual session would proceed as follows:

% reconstruct the PCA compressed data:
% hyper contains the hyperspectral data
% and wlns has the measured wavelength scale that is
% appropriate for the PCA reconstructed image
% (note that wavelength scale does not increase in equal steps)
[hyper, wlns] = readCompressedDAT('file.mat');

% the format of the hyperspectral data:
% rows = number of pixels along the vertical direction
% columns = number of pixels along the horizontal direction
% layers = different wavelength bands (345 bands ranging
% from 396.40nm to 779.61nm. note that the steps are
% not equally sized and are given in the wlns variable)
[r, c, l] = size(hyper);

% plot a spectrum from a random pixel
x = round(rand()*c); y = round(rand()*r);
plot(wlns, squeeze(hyper(y,x,:)))

% convert the hyperspectral image to its linear RGB and
% CIE1931 XYZ representation
[rgb, xyz] = colormatch(hyper);

% gamma correct the linear RGB image
grgb = gammaCorr(rgb);

% display the gamma corrected image
imshow(grgb);

Function descriptions

Summaries of each command in the suite are provided below:

colormatch(hyper)

The colormatch function takes a hyper-spectral image as input and returns two matrices:

To convert from the spectra in the hyperspectral image to corresponding rgb and xyz values, colormatch first goes pixel-by-pixel and applies the following transformations at each pixel: