只能读取dat类型的高光谱数据

以下为头文件

clc
clear all
close allhdr = read_envihdr('d.hdr');
Image = multibandread('d.dat', hdr.size, [hdr.format '=>double'], hdr.header_offset, hdr.interleave, hdr.machine);Image= reshape(Image,hdr.samples*hdr.lines,hdr.bands);

以下为子函数:

function info = read_envihdr(hdrfile)
% READ_ENVIHDR read and return ENVI image file header information.
%   INFO = READ_ENVIHDR('HDR_FILE') reads the ASCII ENVI-generated image
%   header file and returns all the information in a structure of
%   parameters.
%
% Output:
%  * Info - struct with fields provided in the ENVI file. ENVI header
%             format requires the following fields:
%    * samples - number of samples in the image (columns)
%    * lines - number of lines in the image (rows)
%    * bands - number of bands in the image. If all 3 dimensions are
%      provided than info.size will be created holding
%      [info.lines info.samples info.bands]
%    * data_type - data type of the image stored as an integer in 1-15
%      range. If provided than info.format will be created holding string
%      with Matlab's type name.
%    * interleave -  file band interleave type; either bip, bsq, or bil are
%      possible
%    * byte_order - byte order (0 is little endian [least significant
%       byte first], 1 is big endian [most significant byte first]).
%      If provided than info.machine will be created holding either
%      'ieee-le' or 'ieee-be' string.
%
%   Example 1:
%   >> info = read_envihdr('my_envi_image.hdr')
%   info =
%          description: [1x101 char]
%              samples: 658
%                lines: 749
%                bands: 3
%                 size: [749 658 3]
%        header_offset: 0
%            file_type: 'ENVI Standard'
%            data_type: 4
%              format : 'single'
%           interleave: 'bsq'
%          sensor_type: 'Unknown'
%           byte_order: 0
%             map_info: [1x1 struct]
%      projection_info: [1x102 char]
%     wavelength_units: 'Unknown'
%           pixel_size: [1x1 struct]
%           band_names: [1x154 char]
% Example 2:
% >> info = read_envihdr('my_envi_image.hsi');
% >> Z = multibandread(gFile, info.size, [info.format '=>double'], ...
% >>           info.header_offset, info.interleave, info.machine);
%
% Author: Jarek Tuszynski (jaroslaw.w.tuszynski@saic.com)
% License: BSD (Berkeley Software Distribution)
%
% See Also
% * MATLAB function multibandread
% * http://geol.hu/data/online_help/ENVI_Header_Format.html%% If file does not have 'hdr' extension than check if there is an matching
% header file
[FilePath, FileRoot, FileExt] = fileparts(hdrfile);
if ~strcmp(FileExt, '.hdr')fname = hdrfile;hdrfile = [fname '.hdr']; % add '.hdr' to the file nameif ~exist(hdrfile,'file')hdrfile = [FilePath '\' FileRoot '.hdr']; % replace extensionif ~exist(hdrfile,'file')hdrfile = fname;endend
end%% Load whole header file into a string
fid = fopen(hdrfile);
if fid<0, error('%s does not exist. \n', hdrfile); end
str = fread(fid,'uint8=>char')';
fclose(fid);%% split string into lines
flag = 0;
str(str==10) = 13;
str=strrep(str,char([13 13]), char(13));
for i = 1:length(str)switch str(i)case '{'flag=flag+1;case 13if (flag), str(i)=10; end case '}'flag=flag-1;end
end
lines = textscan(str,'%s','Delimiter',char(13));
lines = lines{1};%% parse each line into a field of a struc
info = [];
for iLine=1:length(lines)[info param] = ParseLine(lines{iLine}, info);if ~isempty(param) && ischar(info.(param)) && nnz(info.(param)=='{')% if "{" found than parse one more levelline = info.(param);if nnz(info.(param)=='=')==0 % string has no "=" -> check if it is numeric arrayline(line<32) = [];line(line == '{') = '[';line(line == '}') = ']';num = str2num(line); %#ok<ST2NM>if isnumeric(num) && ~isempty(num)info.(param) = num;elseif nnz(info.(param)==',')>0 % string has "," -> split into string cell arrayline(line == '[' | line == ']') = [];lines2 = textscan(line,'%s','Delimiter',',');info.(param) = lines2{1};endelse                         % string has "="line(line == '{' | line == '}') = [];lines2 = textscan(line,'%s','Delimiter',char(10));lines2 = lines2{1};info2 = [];for jLine=1:length(lines2)info2 = ParseLine(lines2{jLine}, info2);endinfo.(param) = info2;endend
end%% create info.size
if isfield(info, 'lines') && isfield(info, 'samples') && isfield(info, 'bands')info.size = [info.lines info.samples info.bands];
end%% fix 'byte_order' field
if isfield(info,'byte_order')switch info.byte_ordercase 0info.machine = 'ieee-le';case 1info.machine = 'ieee-be';otherwiseinfo.machine = 'n';end
end%% fix 'data_type' field
if isfield(info,'data_type')info.iscomplex=false; %if it is complexswitch info.data_typecase 1info.format = 'uint8';case 2info.format= 'int16';case 3info.format= 'int32';case 4info.format= 'single';case 5info.format= 'double';case 6info.iscomplex=true;info.format= 'single';case 9info.iscomplex=true;info.format= 'double';case 12info.format= 'uint16';case 13info.format= 'uint32';case 14info.format= 'int64';case 15info.format= 'uint64';otherwiseerror(['File type number: ',num2str(dtype),' not supported']);end
endfunction [struc param] = ParseLine(line, struc)param='';eqsn = find(line=='=',1,'first'); % find = signif ~isempty(eqsn)param = strtrim(line(1:eqsn-1));param(strfind(param,' ')) = '_';param = genvarname(param);         % split line into paramvalue = strtrim(line(eqsn+1:end)); % and valueif strcmp(param,upper(param))      % is all letters are upper case than ... param = lower(param);            % convert to lower case stringend% save values as fields of a structtrystruc.(param) = eval(value);    % try converting to numbers, etc.catch ME %#ok<NASGU>struc.(param) = value;endelsestruc.CONTENT = line;end

MATLAB读取高光谱数据相关推荐

  1. Matlab读取二进制数据文件

    第一步:函数fopen打开文件 fid=fopen('文件名',读取方式) fid:句柄值 小于0表示打开失败:大于0表示打开成功 文件名:字符串,使用单引号(本文例子'savedata.dat') ...

  2. MATLAB读取nc数据并显示

    本篇博客主要介绍采用MATLAB读取nc数据并进行显示. 首先是显示经纬度: 示例代码: lon = ncread('met_em.d02.2018-09-12_00_00_00.nc', 'XLON ...

  3. IDL和MATLAB读取grib数据

    IDL读取grib数据 (1)      需要IDL8.1以上版本 (2)      代码如下:        (3)      读取的数据结果在ENVI中查看如下: 可以看到在山东半岛的角上的值为0 ...

  4. MATLAB截取高光谱数据

    MATLAB截取高光谱数据 做图像处理,经常会下载网上的数据库,截取某一部分我们想要的数据进行实验.可能会需要改变数据维度,放大缩小或者是截取,matlab自带的有 resize,reshape等. ...

  5. matlab读取txt数据绘图(python命令行传参)

    (1)命令行实现高斯分布 一:综述 Python唯一支持的参数传递方式是『共享传参』(call by sharing)多数面向对象语言都采用这一模式,包括Ruby.Smalltalk和Java(Jav ...

  6. matlab读取txt数据文件

    一.load()函数 load函数适合读取纯数据文本 例子,data_txt.txt内容如下: 0 1.000000 2.000000 3.000000 1 3.000000 4.000000 5.0 ...

  7. python和matlab读取SST数据(海洋的温度)(.nc文件)并绘图

    第一次写博客,请见谅. 参加学校的预赛,做的是2020年美赛A题.解题思路可查"2020年美赛A题总结",里面有具体的解法.我就不借花谢佛了.下面关于SST数据的读取和绘制虽然繁琐 ...

  8. 基于MATLAB读取高光谱影像每个像素的光谱信息

    1.安装高光谱工具箱 首先,利用MATLAB对高光谱影像进行处理需要安装高光谱工具箱,这要求MATLAB版本至少为2020版本及以上,否则会出现不兼容的问题. 下载地址:https://ww2.mat ...

  9. Matlab读取Eprime数据(txt文档)

    Eprime程序跑完后生成的数据是edat格式,matlab不能直接读取,如果手动merge和export我觉得不太方便,尤其当数据是陆续收集而不是一下子就收好的时候.而且如果两个edat文件的被试或 ...

最新文章

  1. 初识聚类算法:K均值、凝聚层次聚类和DBSCAN 转载的聚类总结
  2. 从封装函数到实现简易版自用jQuery (一)
  3. python守护多线程_Python守护进程(多线程开发)入门实例
  4. java基数排序 数组_万字长文带你掌握Java数组与排序,代码实现原理都帮你搞明白!...
  5. 新年新气象,从SQL Server 2019新特性开始!
  6. Cast-128 加密算法和 MyPassWord 的破解
  7. Azkaban安装部署(附资源)
  8. Fleaphp函数用法举例
  9. 金山毒霸2011进程合并更新 更顺畅运行电脑
  10. 移动前端开发和web前端开发的区别
  11. 【评论精选】关于冯东阳被淘宝索赔一千万事件的用户评论
  12. 第一章 富爸爸,穷爸爸
  13. 【SpringBoot】十八、拦截器 interceptor
  14. Android 自定义view 实现点击 展示下拉选项效果
  15. Prism4学习笔记(七):State-Based Navigation QuickStart
  16. Linux系统磁盘的挂入和装载
  17. 直接灰度变换法matlab,数字图像处理-灰度变换(附MATLAB代码)
  18. 常用dos命令(4)
  19. Mysql查询某个字段多个值最新一条数据
  20. vs配置openNI2以及NiTE2

热门文章

  1. 拍卖理论 英式拍卖 和 荷兰式拍卖 是什么
  2. 5本必读Python入门书籍,你都看过吗?(附福利)
  3. 编程小知识 之 序列 rotate
  4. 失焦的“她营销”,品牌营销困于女性议题
  5. USB2.0实际传输速度为什么与480mbps相差甚远
  6. 子网掩码取反怎么取_求子网掩码最简单,最有效的计算方法。
  7. 一起来看流星雨剧情简介/剧情介绍/剧情分集介绍第十七集
  8. 脑科学读物阅读笔记系列 - 拉马钱德兰《脑中魅影》- 1.初识大脑
  9. 数据库:园林试题软件内容(城市绿地养护服务规范)
  10. 虚拟机Linux挂载新硬盘的方法