%InputMatFileName如D:/360极速浏览器下载/Pavia.mat
%OutputTifFilename如D:/360极速浏览器下载/PaviaTIF.tif
% Mat2Tif('D:/360极速浏览器下载/Pavia.mat','D:/360极速浏览器下载/TifPavia.tif');
function Mat2Tif(InputMatFileName,OutputTifFilename)
load(InputMatFileName);
InputMatImg=label;
t = Tiff(OutputTifFilename,'w');
if size(InputMatImg,3) == 3
t.setTag('Photometric',Tiff.Photometric.RGB);
else
t.setTag('Photometric',Tiff.Photometric.MinIsBlack);%颜色空间解释方式
end
t.setTag('Compression',Tiff.Compression.None);%无压缩
t.setTag('BitsPerSample',64);% 由于输入.mat为double类型,所以选择了64位
t.setTag('SamplesPerPixel',size(InputMatImg,3));% 每个像素的波段数目
t.setTag('SampleFormat',Tiff.SampleFormat.IEEEFP);% 配合BitsPerSample64位double类型,选择IEEEFP来对应
t.setTag('ImageLength',size(InputMatImg,1));% 影像宽度
t.setTag('ImageWidth',size(InputMatImg,2));% 影像高度
t.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);%平面配置选择集中式
t.write(InputMatImg);% 准备好了头文件,开始写影像数据
t.close();% 关闭影像
新建一个脚本文件,输入上述代码。命令行窗口输入
%%其中soup_bigcorn_orange_1ms.mat格式为64位浮点数
Mat2Tif('soup_bigcorn_orange_1ms.mat', 'soup_bigcorn_orange_1ms.tif')