基于MATLAB读取高光谱影像每个像素的光谱信息 | 您所在的位置:网站首页 › 高光谱图像数据提取软件 › 基于MATLAB读取高光谱影像每个像素的光谱信息 |
clear, clc, close all; hcube = hypercube('temp.hdr'); % caijian.hdr 为高光谱数据 datacube = hcube.DataCube; wl = hcube.Wavelength; % lines 为行数,samples 为列数,bands 为波段数 [lines, samples, bands] = size(datacube); % 新建表格用于存放光谱数据,行数为画面中所有像素点的数据,列数包括像素x,y的坐标列和波长列 data_table = zeros(lines*samples, bands+2); % 提取每个点的光谱曲线保存到data_table中 sum = 0; for x = 1:1:lines for y = 1:1:samples sum = sum+1; data_table(sum, 1) = x; % 第一列为像素的行索引 data_table(sum, 2) = y; % 第二列为像素的列索引 spectrum = datacube(x, y, :); spectrum_1d = reshape(spectrum, [1, bands]); data_table(sum, 3:end) = spectrum_1d; % 第三列到最后一列为波段 end end % % 通过两种方式,绘制第3行,第10列像素的光谱曲线,验证提取的光谱曲线是否准确 wl_1d = reshape(wl, [1, bands]); figure, plot(wl_1d, data_table((3-1)*samples+10, 3:end), "LineWidth",5, "Color","blue"); % 从data_table 中取点 hold on; spectrum_1d = reshape(datacube(3, 10, :), [1, bands]); % 从图像中取点 plot(wl_1d, spectrum_1d, "LineWidth", 1, "Color","red"); hold off |
CopyRight 2018-2019 实验室设备网 版权所有 |