1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > matlab读取高光谱影像

matlab读取高光谱影像

时间:2022-10-09 10:48:03

相关推荐

matlab读取高光谱影像

1.函数multibandread读取读取多波段二进制影像文件(ENVI主菜单file—save file as—envi standard得到的就是二进制影像文件,有时甚至会看到后缀名为bsq、bil、bip等影像)。

im_hyper = multibandread(filename, size, precision, offset, interleave, byteorder)

后附参考代码有实例

filename: 文件名 size:图像尺寸和波段数,size = [ 行数 列数波段数 ] precision:读取的图像的数据格式,例如'uint8','uint16','double'等 offset:偏移(一般为0) interleave:存储的图像的数据格式,有 bsq,bil,bip三种格式 byteorder : 数据存储的字节排列方式,有'ieee-le'(小端),'ieee-be'(大端) 注:precision参数与matlab数据类型相应的关系(FORM/use-matlab-read-envi-image.html,辛苦博主整理。) (

precision='uint8=>uint8';%头文件中datatype=1对应ENVI中数据类型为Byte,对应MATLAB中数据类型为uint8

precision='int16=>int16';%头文件中datatype=2对应ENVI中数据类型为Integer,对应MATLAB中数据类型为int16

precision='uint16=>uint16';%头文件中datatype=12对应ENVI中数据类型为Unsighed Int,对应MATLAB中数据类型为uint16

precision='int32=>int32';%头文件中datatype=3对应ENVI中数据类型为Long Integer,对应MATLAB中数据类型为int32

precision='uint32=>uint32';%头文件中datatype=13对应ENVI中数据类型为Unsighed Long,对应MATLAB中数据类型为uint32

precision='float32=>float32';%头文件中datatype=4对应ENVI中数据类型为Floating Point,对应MATLAB中数据类型为float32

precision='double=>double';%头文件中datatype=5对应ENVI中数据类型为Double Precision,对应MATLAB中数据类型为double

) 2. 如果是.tif格式的图像,可先使用envi将其转化为envi standard 格式,然后使用enviread读取 ENVI软件标准格式的高光谱遥感图像含有两部分: 一个是高光谱图像 '*.img ', 另一个是遥感图像头文件 '*.hdr',该文件记录了遥感图像的信息,如图像尺寸、波段数、数据类型和大小端等。如果缺少头文件,将无法对遥感图像进行读取 读取代码:来源:/use-matlab-read-envi-image.html, 亦可参考:/s/blog_16ecb33400102ybql.html

function data=read_ENVIimagefile(imgfilename)%本函数读取img格式,前提是img图像显式带有'.img'后缀名。if length(imgfilename)>=4switch strcmp(imgfilename(length(imgfilename)-3:end), '.img')case 0hdrfilename=strcat(imgfilename, '.hdr');case 1hdrfilename=strcat(imgfilename(1: (length(imgfilename)-4)), '.hdr');endelsehdrfilename=strcat(imgfilename, '.hdr');end%读取ENVI标准格式图像文件%读取图像头文件fid = fopen(hdrfilename, 'r');info = fread(fid,'char=>char');info=info';%默认读入列向量,须要转置为行向量才适于显示fclose(fid);%查找列数a=strfind(info,'samples = ');b=length('samples = ');c=strfind(info,'lines');samples=[];for i=a+b:c-1samples=[samples,info(i)];endsamples=str2num(samples);%查找行数a=strfind(info,'lines = ');b=length('lines = ');c=strfind(info,'bands');lines=[];for i=a+b:c-1lines=[lines,info(i)];endlines=str2num(lines);%查找波段数a=strfind(info,'bands = ');b=length('bands = ');c=strfind(info,'header offset');bands=[];for i=a+b:c-1bands=[bands,info(i)];endbands=str2num(bands);%查找数据类型a=strfind(info,'data type = ');b=length('data type = ');c=strfind(info,'interleave');datatype=[];for i=a+b:c-1datatype=[datatype,info(i)];enddatatype=str2num(datatype);precision=[];switch datatypecase 1precision='uint8=>uint8';%头文件中datatype=1对应ENVI中数据类型为Byte,对应MATLAB中数据类型为uint8case 2precision='int16=>int16';%头文件中datatype=2对应ENVI中数据类型为Integer,对应MATLAB中数据类型为int16case 12precision='uint16=>uint16';%头文件中datatype=12对应ENVI中数据类型为Unsighed Int,对应MATLAB中数据类型为uint16case 3precision='int32=>int32';%头文件中datatype=3对应ENVI中数据类型为Long Integer,对应MATLAB中数据类型为int32case 13precision='uint32=>uint32';%头文件中datatype=13对应ENVI中数据类型为Unsighed Long,对应MATLAB中数据类型为uint32case 4precision='float32=>float32';%头文件中datatype=4对应ENVI中数据类型为Floating Point,对应MATLAB中数据类型为float32case 5precision='double=>double';%头文件中datatype=5对应ENVI中数据类型为Double Precision,对应MATLAB中数据类型为doubleotherwiseerror('invalid datatype');%除以上几种常见数据类型之外的数据类型视为无效的数据类型end%查找数据格式a=strfind(info,'interleave = ');b=length('interleave = ');c=strfind(info,'sensor type');interleave=[];for i=a+b:c-1interleave=[interleave,info(i)];endinterleave=strtrim(interleave);%删除字符串中的空格%读取图像文件fid = fopen(imgfilename, 'r');data = multibandread(imgfilename ,[lines, samples, bands],precision,0,interleave,'ieee-le');data= double(data);end

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。