function [lxw,XO,wl]= HSIFileOpen(lxwfilepath,HSIfilepath)
%HSIFileOpen函数用来打开高光谱影像数据
%lxwfilepath--头文件全路径
%HSIfilepath--高光谱数据全路径
%打开文件
fp1 = fopen(lxwfilepath,'r');
fp2 = fopen(HSIfilepath,'r');
%读取头文件
lxw=fscanf(fp1,'%f');
bands = lxw(1);%波段数
datatype = lxw(2);%字节数
samples = lxw(3);%列数
lines = lxw(4);%行数
columns = samples*lines;%像元个数
switch lxw(5)%数据格式
case 0
interleave = 'bsq';
case 1
interleave = 'bil';
case 2
interleave = 'bip';
case 3
interleave = 'mat';
end
%读取高光谱数据二进制文件
switch datatype
case 1
precision = 'uint8';
case 2
precision = 'uint16';
case 4
precision = 'float32';
end
if interleave == 'bsq'
XO = fread(fp2,[columns,bands],precision);
XO = XO';
elseif interleave == 'bil'
tmp = fread(fp2,[samples,bands*lines],precision);
XO = zeros(bands,columns);
for i=1:bands
for j=1:lines
XO(i,((j-1)*samples+1):j*samples) = tmp(:,(j-1)*bands+i);
end
end
elseif interleave == 'bip'
XO = fread(fp2,[bands,columns],precision);
elseif interleave == 'mat'
XO = fread(fp2,[bands,columns],precision);
end
b = lxw(6);%该参数判断有没有波长数据
if b==1
token = strtok(HSIfilepath,'.');
wavelengthpath = strcat(token,'.wl');
fp3 = fopen(wavelengthpath,'r');
wl=fscanf(fp3,'%f');
%关闭文件
fclose(fp3);
else
wl = 0;
end
%关闭文件
fclose(fp1);
fclose(fp2);
- 1
- 2
- 3
- 4
- 5
- 6
前往页