当前位置:网站首页>MATLAB中对tif格式栅格影像读取-保存
MATLAB中对tif格式栅格影像读取-保存
2022-06-09 23:01:00 【石头变钻石?】
MATLAB中对tif格式栅格影像读取-保存,点滴学习,贵在记录。
MATLAB中对tif格式栅格影像读取-保存
在做水质反演的过程中,用到了MATLAB,但对这个工具一无所知。研究的总体思路是先建立整体构架,然后查阅每一步的具体实现的语法,结合MATLAB help,逐渐实现每一步。
geotiffwrite
基础语法
geotiffwrite(filename,A,R)
geotiffwrite(filename,X,cmap,R)
geotiffwrite(…,Name,Value)
输入参数变量释义:
filename:输入文件的名称和位置,文件扩展名必须是 “.tif” 或者 “.TIF”,变量类型为字符向量。
A:要导出的影像数据,为MNP的矩阵。坐标系为地理坐标,且默认为WGS-84,指定坐标可通过’GeoKeyDirectoryTag’和’CoordRefSysCode’实现。数据类型
数据类型 double | single | uint8 | uint16 | uint32 | uint64 | int8 | int16 | int32 | int64 | logical
R:空间参考信息。
空间引用信息,指定为地理栅格引用对象、引用矩阵或引用向量。
如果您正在处理投影坐标系中的图像坐标,而R是一个地图栅格引用对象或引用矩阵,则相应地指定“GeoKeyDirectoryTag”或“CoordRefSysCode”。
X:待补充
cmap:RGB图像,为M*3的矩阵
示例
% 影像的读取
basename = 'boston_ovr';
imagefile = [basename '.jpg'];
RGB = imread(imagefile);
worldfile = getworldfilename(imagefile);
R = worldfileread(worldfile, 'geographic', size(RGB)); %读取空间参考信息
%导出影像
filename = [basename '.tif'];
geotiffwrite(filename, RGB, R)
% 显示影像
figure
usamap(RGB, R)
geoshow(filename)
示例2 读取tif处理后保存tif
% 读取tif及空间坐标信息
[A, R] = geotiffread('F:\boston.tif');
info = geotiffinfo('F:\boston.tif');
% 保存tif并使用原始数据空间坐标信息
subimage = A;
subR = R;
filename = 'boston_subimage.tif';
geotiffwrite(filename, subImage, subR, ...
'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
figure
mapshow(filename);
其他参数较多,可以从原始影像中读取,也可以自定义。
‘CoordRefSysCode’ :坐标系,默认EPSG:4326(即WGS84坐标系)
使用方法:'CoordRefSysCode',4326
小知识,EPSG:4326是web map中用来表示地图坐标的代码,每个坐标都有一个对应的EPSG代码,常用的WGS84代码为EPSG:4326,伪墨卡托投影代码为EPSG:3857
‘TiffTags’:结构体,内容有以下
| Compression | 压缩类型,默认‘PackBits’,其他的包括‘LZWZ’,‘Deflate’,‘none’ |
|---|---|
| PhotometricInterpretation | 一般不需要设置。官方介绍如下:字段名称可以缩短为光度控制。该值是根据输入图像特征设置的,使用以下算法:如果A是[M-by-N-by-3],并且是类类型uint8或uint16,则该值为“RGB”。对于所有其他大小和数据类型,该值为“miniBlack”。如果提供了X,CMAP语法,则值为“palete”。如果该值设置为“RGB”,而A不是[M-by-N-by-3],则会发出错误。允许的值为“miniBlack”、“RGB”、“Palette”、“Separated”。 |
| Software | 可忽略,,,,文件的软件制造商。该值设置为“MATLAB,Mapping Toolbox,The MathWorks,Inc.”的值。要删除该值,请将标记设置为空字符串或字符向量(’’)。 |
| RowsPerStrip | 一个标量正整数值,指定输出文件中每个条带所需的行数。如果A的大小小于[160 x 160],geotiffwrite将RowsPerStrip设置为1。如果指定RowsPerStrip和TileWidth,无论是否使用tillelength,geotiffwrite都会发出错误。 |
| TileWidth | 标量正整数值和16的倍数,指定分片的宽度。如果A的大小大于[160 x 160],则设置平铺宽度。如果是,则该值将创建最多[10×10]个平铺。如果同时指定RowsPerStrip和TileWidth,geotiffwrite将发出错误。 |
| TileLength | 同上,长度 |
使用方法:tifftags = sturct('Compression','LZW')
重点!!!
之前跑数据时,发现超过4GB的数据无法写入保存,这是因为geotiff有两种格式,一种是classictiff,另外一种是针对大数据的bigtiff。解决此办法就是加入字段geotiffwrite(name,out,R,....,'TiffType','bigtiff','Tifftags',tifftags)
老版本的没有这个,如果报错,请注意版本问题。目前用的19a没有问题
边栏推荐
- C# WPF 实现Tab页动态增减
- sparksql源码系列 | 一文搞懂Partitioning源码体系(spark3.2)
- jg-文件上传代码-以及导出excel
- cadence SPB17.4 - allegro - use keyboard move part on grid offset by our setting
- 双塔模型-语义索引策略 [In-batch Negatives]
- 2022爱分析· 隐私计算厂商全景报告 | 爱分析报告
- 騰訊-NCNN簡介
- qnx系统学习
- Swift GCD Notify after concurrent execution Lock barrier
- Experiment 1: configure static routes on FW to realize interworking
猜你喜欢

蓝桥杯_分割立方体_组合数学_加法原理

只需八步将小程序一键打包生成App

"At the age of 35, I have no sideline, so I'm embarrassed to mix in the workplace": get rid of the sideline of dead salary recommendation

2022 love analysis · privacy computing vendor panoramic report | love Analysis Report

Record the 'new' course of an emergency investigation
Deploy MySQL based on statefulset in kubernetes (Part 1)

我服了,MySQL表500W行,居然有人不做分区?

Server operation and maintenance environment security system (Part 2)

Implementation of ngnix dynamic reading environment variables

Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup
随机推荐
Microsoft Word 教程「4」,如何在 Word 中应用样式、主题?
Two tower model: Ernie gram pre training and fine-tuning matching
有没有必要考取PMP?
Microsoft Word tutorial "4", how to apply styles and themes in word?
String-4-242. 有效的字母异位词
服务器运维环境安全体系(下篇)
This configuration section cannot be used in this path. If the section is locked at the parent level, the solution to this situation will occur
2022年金属非金属矿山爆破考试题库及答案
Detailed explanation of IEEE 754 floating point number standard
I haven't seen this knowledge -- MySQL service evolution
JG file upload code and export Excel
What is a distributed software system
How does uni app build applets?
双塔模型:ERNIE-Gram预训练精排Matching
15 张图带你深入理解浮点数
iOS 缓存 -- NSCache和沙盒缓存
Project training (XV) -- Video multi character recognition supplement
项目实训(十五)---视频多人物识别补充
Virtual machine environment configuration record 1
Repeated web1 history in Web3