当前位置:   article > 正文

高光谱数据Mat文件转换为TIFF文件_mat文件转tif

mat文件转tif

由于近期需要使用Hyperspectral Remote Sensing Scenes中的高光谱数据,所以特地记录一下数据处理的过程。

由于Mat文件时MATLAB中特有的文件,所以需要敲一些代码,但是整个过程是比较简单的,如下所示。

clc
clear
close all
%获取Mat文件
[fileName,pathName]=uigetfile('*.mat','Input Data-File');

if isempty(fileName) || length(fileName) == 1
    fprintf("未选择mat文件!\n");
    return;
end
fullPath = [pathName,fileName];
% load(fullPath);
image = importdata(fullPath);
shape = size(image);
dirName = fileName(1:length(fileName)-4);
dirPath = [pathName,dirName];
if exist(dirPath,'dir')==0
	mkdir(dirPath);
end

if length(shape) < 3
    fprintf("该文件不是多光谱数据\n");
    image = uint16(image);         %将灰度值转换为16bit
    str = [dirPath,'\',dirName,'.tif'];
    imwrite(image,str,'tif');
    return;
end
fprintf("输入数据的波段数量%d\n",shape(3));

for i=1:shape(3)
    band = image(:,:,i);
    band = uint16(band);         %将灰度值转换为16bit
    str=sprintf('B%d.tif',i);
    str = [dirPath,'\',dirName,str];
    imwrite(band,str,'tif');
    fprintf("输出波段%d\n",i);
end

  • 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

处理之后的效果:

在这里插入图片描述
在这里插入图片描述

特别要注意的是,灰度值要转换成16bit深度,否则有的影像呈现出来会全是黑色。此外就是这种转换出的tif文件是没有地理坐标的,所以如果要使用ENVI进行波段融合,还需要手动的进行地理配准*^*。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号