Skip to content

Instantly share code, notes, and snippets.

@ilyakava
Last active March 27, 2023 02:00
Show Gist options
  • Save ilyakava/1a2a6ef254603495379db6335573c506 to your computer and use it in GitHub Desktop.
Save ilyakava/1a2a6ef254603495379db6335573c506 to your computer and use it in GitHub Desktop.
matlab hsi data reading from raster file for KSC
% // References:
% // http://www.ehu.eus/ccwintco/uploads/d/dc/LoadHypercubesMatlab.pdf
% data can be downloaded from:
% http://www.csr.utexas.edu/hyperspectral/data/KSC/KSC_data.bin
% http://www.csr.utexas.edu/hyperspectral/data/KSC/KSC_data.bin.hdr
% compare
% cd /scratch0/ilya/locDoc/data/hyperspec/datasets/
im = multibandread('KSC_data.bin', [512 614 176], 'uint16', 0, 'bsq', 'ieee-le');
im2 = multibandread('KSC_data.bin', [512 614 176], 'int16', 0, 'bsq', 'ieee-be');
% // check histograms like so
histogram(im2(:,:,1))
title('channel 1 int16')
figure
histogram(im(:,:,1))
title('channel 1 uint16')
% // you will find that KSC_data.bin.hdr is wrong. The datatype is 2 (int16) not 12 (uint16)
% channels that are seriously affected: 1,3,4,60-62,65,69-71,73,78-176
KSC = im2;
save('KSC_corrected.mat', 'KSC')
% compare with website data from here:
% http://www.ehu.eus/ccwintco/index.php/Hyperspectral_Remote_Sensing_Scenes
% http://www.ehu.es/ccwintco/uploads/2/26/KSC.mat
% cd /scratch0/ilya/locDoc/data/hyperspec/datasets/
web_data = load('KSC.mat');
web = web_data.KSC;
sum(sum(sum(web == im))) == (512*614*176)
% => logical 1
@ilyakava
Copy link
Author

ilyakava commented Feb 8, 2021

hsikscall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment