赞
踩
clear close all clc hdr_path_name = 'G:\cs\DATA_lyx_1.hdr'; fid = fopen(hdr_path_name,'r'); info = fread(fid,'char=>char'); info = info'; fclose(fid); start = strfind(info,'samples = '); len = length('samples = '); stop = strfind(info,'lines '); samples = []; for i = start+len : stop-1 samples = [samples,info(i)]; end samples = str2num(samples); start = strfind(info,'lines = '); len = length('lines = '); stop = strfind(info,'bands'); lines = []; for i = start+len : stop-1 lines = [lines,info(i)]; end lines = str2num(lines); start = strfind(info,'bands = '); len = length('bands = '); stop = strfind(info,'header offset'); bands = []; for i = start+len : stop-1 bands = [bands, info(i)]; end bands = str2num(bands); start = strfind(info,'data type = '); len = length('data type = '); stop = strfind(info,'interleave'); datatype = []; for i = start+len : stop-1 datatype = [datatype, info(i)]; end datatype = str2num(datatype); precision = []; switch datatype case 1 precision = 'uint8 => uint8'; case 2 precision = 'int16 => int16'; case 12 precision = 'uint16 => uint16'; case 3 precision = 'int32 => int32'; case 13 precision = 'uint32 => uint32'; case 4 precision = 'float32 => float32'; case 5 precision = 'double => double'; otherwise precision = 'invalid type'; end start = strfind(info,'interleave = '); len = length('interleave = '); stop = strfind(info,'sensor type'); interleave = []; for i = start+len : stop-1 interleave = [interleave, info(i)]; end interleave = strtrim(interleave); data = multibandread('G:\cs\DATA_lyx_1.bsq',[lines,samples,bands],precision,0,interleave,'ieee-le',{'Row','Range',[1 256]},{'Column','Range',[1 256]});
需要注意的几个点(影响代码跑通的最关键几个因素):
hdr_path_name = 'G:\cs\DATA_lyx_1.hdr';
此处的hdr文件目录要换成自己所存储的高光谱图像目录
data = multibandread('G:\cs\DATA_lyx_1.bsq',[lines,samples,bands],precision,0,interleave,'ieee-le',{'Row','Range',[1 256]},{'Column','Range',[1 256]});
此处的图像路径也要改为自己的文件路径
关于{'Row','Range',[1 256]},{'Column','Range',[1 256]}中的256不是绝对的,这个是由图像的samples和lines来决定的,也可能是512,1024等。可以打开hdr文件查看
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。