Matlab
Deprecated
These are legacy examples from before the HV SDK became the recommended interface for HSI datacubes and Hypervision cameras.
Use the HV SDK Tutorials and Examples for current Python workflows, including file I/O, calibration, PCA, classification, regression, and camera streaming.
Reading PAM datacubes
msp_HSI_buteo.m
function cube = msp_HSI_buteo(file_path)
% msp_HSI_buteo - Reads and reshapes a hyperspectral image cube from a .pam file.
%
% This function reads a SWIR hyperspectral image stored in a .pam file and
% reshapes it into a 3D cube format.
%
% Author: msp
% Date: February 2025
%
% Input:
% file_path - String specifying the path to the .pam file.
%
% Output:
% cube - A 3D hyperspectral image cube (height x width x bands).
%
% Note:
% - The function assumes a specific file format where the first 11 lines
% form a header that is ignored.
% - The reshaping assumes a fixed image size of 1296 (height) × variable width × 900 (bands).
%
% Open file for reading
fileID = fopen(file_path, 'r');
if fileID == -1
error('Error: Could not open file %s', file_path);
end
% Read and store the first 11 lines as header
header = [];
for i = 1:11
header = [header, fgets(fileID)]; % Read header, one line at a time
end
byte_length = numel(header); % Byte length of header (not used)
% Read the rest of the .pam file (excluding header)
data = uint8(fread(fileID)); % Read as unsigned 8-bit integer
% Close the file
fclose(fileID);
% Reshape data into a 3D hyperspectral cube
cube = reshape(data, 1296, [], 900); % SWIR Buteo assumed dimensions
% Clear unnecessary variable
clear data;
end
PAM interleave
The above example expects PAM files captured using the Buteo Hyperspectral Imaging System which have a BSQ interleave type.
Reflectance transformation
msp_refl_trans.m
function cube_refl = msp_refl_trans(cube, mean_white, mean_dark)
% msp_refl_trans - Performs reflectance transformation on a hyperspectral image cube.
%
% This function converts raw hyperspectral intensity values into reflectance values
% using a white reference and a dark reference.
%
% Author: msp
% Date: February 2025
%
% Input:
% cube - A 3D hyperspectral image cube (height x width x bands).
% mean_white - A reference white image (same dimensions as cube or a single spectrum).
% mean_dark - A reference dark image (same dimensions as cube or a single spectrum).
%
% Output:
% cube_refl - The hyperspectral cube transformed to reflectance values.
% Compute reflectance transformation
cube_refl = single(cube - uint8(mean_dark)) ./ single(uint8(mean_white - mean_dark));
% Handle NaN and Inf values (caused by division by zero)
cube_refl(isnan(cube_refl) | isinf(cube_refl)) = 0;
cube_refl = single(cube_refl);
end