matlab 保存tif文件,保存多波段图像到tif文件

本文详细介绍如何将MATLAB中的高光谱数据(mat文件)转换并保存为200个波段的tif图像文件,包括代码实现及关键步骤解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将mat文件,保存为tif

以高光谱IndiaP数据为例,保存为200个波段的tif文件。

% mat2tif
% 将高光谱mat文件,保存为tif
clc; clear; close all;

%% load the hyperspectral image
path = './';
dataset = 'IndiaP';

location = [path, dataset];
load (location);

% 获取数组维度信息
[row, col, bands] = size(img);

% double类型转unit8
img_8 = uint8(img(:,:,:)/10000*256);

% 保存为tif图像
t = Tiff('imageIndiaP.tif','w');
% 影像信息
tagstruct.ImageLength = size(img_8,1); 
tagstruct.ImageWidth = size(img_8,2);  

% 颜色空间解释方式
tagstruct.Photometric = 1;

% 每个像素的数值位数,这里转换为unit8,所以为8位
tagstruct.BitsPerSample = 8;
% 每个像素的波段个数,一般图像为1或3,但是对于遥感影像存在多个波段所以常常大于3
tagstruct.SamplesPerPixel = bands;
tagstruct.RowsPerStrip = 16;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% 表示生成影像的软件
tagstruct.Software = 'MATLAB'; 
% 表示对数据类型的解释
tagstruct.SampleFormat = 1;
% 设置Tiff对象的tag
t.setTag(tagstruct);

% 以准备好头文件,开始写数据
t.write(img_8);
% 关闭影像
t.close;

代码和数据集:
https://download.csdn.net/download/Eric_Fisher/12049897

评论 23
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值