matlab与geotiff影像的函数,用法介绍
文章目录
- 前言
- 一、matlab和geotiff相关函数的学习
- (1) pix2latlon() 和latlon2pix()
- (2) pix2map() 和 map2pix()
- (3) projfwd() 和 projinv()
- (4) geotiffread()
- (5) geotiffinfo()
- (6) worldfileread()
- (7) .tif 和 .tfw
- 二、matlab 实现对geotiff影像的拼接
- 三. geotiff影像进行resize,并修改坐标信息
前言
matlab给影像加地理坐标信息,一直没有很系统的明白,现在学习并记录吧
一、matlab和geotiff相关函数的学习
(1) pix2latlon() 和latlon2pix()
pix2latlon()和latlon2pix()是对经纬度坐标系的影像,实现**像素坐标**和**经纬度坐标**的转换
%% (1)pix2latlon( ) [lat,lon]=pix2latlon(R,row,col)
% latlon2pix() [row,col]=pix2latlon(R,lat,lon)
%自己的理解: 应该是对地理坐标系的影像,进行像素坐标系和地理坐标系的转换。
% R是 geotiff影像的info.RefMatrix(3行2列),或者是一个 a geographic raster reference object.
img_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect.tif';
row=100;col=100;
[A,refmat,bbox] = geotiffread(img_name);% geotiffread的第二个参数就是geotif 的info.RefMatrix
info = geotiffinfo(img_name);
R=info.RefMatrix
[lat,lon]=pix2latlon(R,row,col);
% [lat,lon]=pix2latlon(refmat,row,col);
% R的读取,可以用过geotiffread,也可以通过geotiffinfo,info.RefMatrix
(2) pix2map() 和 map2pix()
(1)pix2map()和map2pix()是对投影坐标系的影像,实现**投影坐标**<--->**像素坐标**的转换
(2)当然,也可以实现**像素坐标**和**经纬度坐标**的转换,需要借用projfwd()和projinv()函数
%% (2)pix2map() [x,y] = pix2map(R,row,col)
% map2pix()
img_utm_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect_utm_tif.tif';
img_utm_tfw_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect_utm_tif.tfw';
[X,cmap] = imread(img_utm_name);
R = worldfileread(img_utm_tfw_name,'planar',size(X));
[x,y] = pix2map(R,100,50);
(3) projfwd() 和 projinv()
实现在投影坐标系下的影像,在**像素坐标**<--->**经纬度坐标**之间的转换
%% projfwd (forward mapprojection from lat and lon to map coordinate x,y )
img_utm_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect_utm_tif.tif';
img_utm_tfw_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect_utm_tif.tfw';proj=geotiffinfo(img_utm_name);
[x,y]=projfwd(proj,50.2,124.3);
%% projinv (inverse mapprojection from map coordinate to lat and lon)
img_utm_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect_utm_tif.tif';
img_utm_tfw_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect_utm_tif.tfw';proj=geotiffinfo(img_utm_name);
[x,y]=projinv(proj,x,y);
(4) geotiffread()
[img,rotate_matrix]=geotiffread(filename);
[img,colormap,rotate_matrix]=geotiffread(filename);
[img,referencematrix,bbox]=geotiffread(filename);
[img,colormap,referenceematrix,bbox]=geotiffread(filename);
(5) geotiffinfo()
%% geotiffinfo 返回的info是 a structure whose fields contain image properties and catographic infofrmation and a geotiff fileinfo=geotiffinfo(filename);
(6) worldfileread()
使用worldfileread这个函数需要有两个文件 **tif**和**tfw**
%% worldfileread (read world file and return referencing object or matrix)
% 用这个函数,geotiff影像需要有2个文件: filename.tif + filename.tfw
% 主要区别是: 'geographic'--> latitude-longtitude system
% 'planar'--> projected map coordinate
img_utm_name='E:\2022_5_2_GF_pa1_pa2_lens_rect\pa1_012_006\mapproject\pm1_006_6087_2_12116_sub_ba_rect_utm_tif.tif';
img=imread(img_utm_name);
worldfilename=getworldfilename(img_utm_name);
R=worldfileread(worldfilename,'planar',size(img));
(7) .tif 和 .tfw
%% (1)tif tfw 文件的详细介绍: https://zhuanlan.zhihu.com/p/365157364
% (2)python为geotif文件创建tfw文件:https://qastack.cn/gis/9421/creating-tfw-and-prj-files-for-folder-of-geotiff-files
二、matlab 实现对geotiff影像的拼接
%% mosaic 2 images (要求: 2张影像地理坐标投影:geographic,或者是 投影坐标系 ,但是两张影像行列数一致等基本信息一致)X_west = imread('D:\matlab_mosaic\left.tif');
X_east = imread('D:\matlab_mosaic\right.tif');
X = [X_west X_east];% 影像为地理坐标投影 下面函数的参数为: 'geographic'
% 若影像为投影坐标系, 则函数参数为: 'planar'R_west = worldfileread('D:\matlab_mosaic\left.tfw', 'geographic', size(X_west));
R_east = worldfileread('D:\matlab_mosaic\right.tfw', 'geographic', size(X_east));
R = R_west;
R.XLimWorld = [R_west.XLimWorld(1) R_east.XLimWorld(2)];
R.RasterSize = size(X);
out_f='D:\matlab_mosaic\mosaic_li2.tif';% 下面的coordRefSysCode 代码4326为WGS 经纬度坐标系。与原始影像对应。
% 若原始影像为投影坐标系,则修改 coordRefSysCode 即 找一些对应的EPSG code
coordRefSysCode = 4326;
geotiffwrite(out_f, X, R,'CoordRefSysCode', coordRefSysCode);
三. geotiff影像进行resize,并修改坐标信息
[A,RA] = readgeoraster([files(i).folder,'\',files(i).name]);B = imresize(A, 0.5);% 修改影像的地理坐标信息RA.CellExtentInLatitude = RA.CellExtentInLatitude * 2;RA.CellExtentInLongitude = RA.CellExtentInLongitude * 2;RA.RasterSize = size(B);% 保存为geotif文件geotiffwrite([resize_files_folder,files(i).name], B, RA);
matlab与geotiff影像的函数,用法介绍相关推荐
- python中mean的用法_python 的numpy库中的mean()函数用法介绍
1. mean() 函数定义: numpy.mean(a, axis=None, dtype=None, out=None, keepdims=)[source] Compute the arithm ...
- python 的numpy库中的mean()函数用法介绍
这篇文章主要介绍了python 的numpy库中的mean()函数用法介绍,具有很好对参考价值,希望对大家有所帮助.一起跟随小编过来看看吧 mean() 函数定义: 2 mean()函数功能: 求取均 ...
- python average函数怎么用_python 的numpy库中的mean()函数用法介绍
1. mean() 函数定义: numpy.mean(a, axis=None, dtype=None, out=None, keepdims=)[source] Compute the arithm ...
- C#中ToInt32以及类似函数用法介绍
C#中ToInt32以及类似函数用法介绍 作用 程序举例 程序逻辑 程序代码 程序 作用 将指定的值转换为 32 位有符号整数.对应的还有ToInt16,ToInt64 指定的值可以是字符串.时间.位 ...
- matmul/mm 函数用法介绍
介绍torch.matmul之前先介绍torch.mm函数, mm和matmul都是torch中矩阵乘法函数,mm只能作用于二维矩阵,matmul可以作用于二维也能作用于高维矩阵 mm函数使用 x = ...
- Matlab中repmat、permute函数用法
repmat函数用法 复制和平铺矩阵 函数repmat 格式: B = repmat(A, m, n) %将矩阵A复制m*n块,即B由m*n块A平铺而成 B = repmat(A, [m n])%与 ...
- matlab中find()函数用法
一.基本用法 返回矩阵或向量中非零元素的索引 注意:matlab中下标从1开始 举例: (1)向量 返回非零元素下标 find(vector) x=[1 2 3 0 0 6 7 8 9]; find( ...
- c语言strTrimed函数用法介绍,linux type命令用法_转
在脚本中type可用于检查命令或函数是否存在,存在返回0,表示成功:不存在返回正值,表示不成功. $ type foo >/dev/null 2>&1 || { echo > ...
- c语言strTrimed函数用法介绍,TRIM函数
[TRIM函数]的更多相关文章 三个Trim函数简介 函数原型 function Trim(const S: string): string; 将字符串前后的空白及控制字元清掉. 注意Trim函数只能 ...
最新文章
- wxWidgets:wxSizeEvent类用法
- [小技巧][JAVA][转换]字符数组char[]与字符串String之间互相转换
- 用python一行代码实现1—100之和,你会吗
- 【JAVASCRIPT】如何不使用jquery函数和ajax框架实现ajax效果
- 转:Ruby 的性能 与如何选用正确的framework来做web
- java 日志切面_自定义注解+面向切面整合的日志记录模块(一)
- 推荐系统组队学习——矩阵分解和FM
- HTML中更改hr宽度高度颜色
- Redis后门植入分析报告
- 【Linux系统编程】| 【01】系统编程基本概念
- 标题:深度分销的方向和尺度 内容:Pnbsp;深度分销的方向和尺度BRnbsp;nbsp; 所谓深度分销,有人也称之为通路精耕细作,是通过减少原有渠道层次,并增强中间商分销能力或通过企
- 网易前端JavaScript编码规范
- 【BZOJ1001】狼抓兔子
- urllib库爬取拍信创意图片(post请求)json传参
- 2020年第三季度的垃圾邮件和网络钓鱼攻击分析
- zynq linux环境移植,ZYNQ 7030 Linux 系统移植
- SkyLight 添加LightingChannelMask功能
- 【深入kotlin】 - 协程的取消
- C语言编程>第一周 ③ 输入某年某月某日,判断这一天是这一年的第几天
- 英文网站推广常用方法有哪些