1、前言
研究需要需要展示高光谱图像的3维立体图,因此用chatgpt帮忙写了一个。用于转换HSI CD的.mat格式的数据集。
2-代码
%%
clc; clear; close all;
% load the hyperspectral image
img = load ('USA_Change_Dataset.mat');
img = img.T1;
% 提取高光谱数据的维度信息
[rows, cols, bands] = size(img); % 替换为你的高光谱数据变量名
% 创建一个空白的TIFF图像
tiff_img = zeros(rows, cols, bands, 'uint16'); % 使用uint16数据类型以保留高光谱数据的精度
% 将高光谱数据复制到TIFF图像中
for band = 1:bands
tiff_img(:,:,band) = img(:,:,band);
end
% 保存TIFF图像
tiff_filename = 'output_image.tif'; % 替换为你想要保存的TIFF文件名和路径
t = Tiff(tiff_filename, 'w');
% 设置TIFF图像的属性
tagstruct.ImageLength = size(tiff_img, 1);
tagstruct.ImageWidth = size(tiff_img, 2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 16;
tagstruct.SamplesPerPixel = bands;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.ExtraSamples = Tiff.ExtraSamples.Unspecified;
tagstruct.Software = 'MATLAB';
% 写入图像数据
t.setTag(tagstruct);
t.write(tiff_img);
t.close();
disp('MAT格式的高光谱数据已成功转换为TIFF格式!');
3-ENVI效果展示
ENVI将读取tiff格式图像,然后展示3维立体图