当前位置:   article > 正文

matlab将mat格式高光谱图像转为tif格式_高光谱数据mat转tiff matlab

高光谱数据mat转tiff matlab

高光谱图像mat格式转为tif格式

以高光谱IndiaP数据为例,保存为200个波段的tif文件。ENVI软件只能读入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;
% 每个像素的波段个数,一般图像为13,但是对于遥感影像存在多个波段所以常常大于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;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/338627
推荐阅读
相关标签
  

闽ICP备14008679号