Matlab 读取—处理—保存遥感影像(带有地理信息的图像)

读取—处理—保存遥感影像(带有地理信息的图像
Matlab读取遥感影像的函数是
简介
数据读取 

[A,R] = geotiffread(filename) ;
 
 

Reads a georeferenced grayscale, RGB, or multispectral image or data grid from the GeoTIFF file specified by filename into A and creates a spatial referencing object, R.(官方解释)。

描述一下就是 代表的数据文件(高程之类的数据),为空间坐标信息(包括数据的大小,经纬度范围与起始经纬度,数据单位、方向等)。

读取部分到此为止!

2)数据处理

我这里主要介绍的数据的裁剪(比如要从一块数中选择其中的某一部分画图等)。

我们应该很清楚在做数据裁剪时会用到Matlab的冒号(:)函数,这个也是很简单。但是我们在对含有地理坐标的数据进行裁剪时,经纬度信息也要对应数据裁剪的办法进行裁剪。


 
 
  1. Start_Latitude = 0.6;
  2. End_Latitude = 0.8;
  3. Start_Lontitude = 0.1;
  4. End_Lontitude = 0.3;

以上四个部分是裁剪的核心部分,只要修改对应的这四个值就可以选择裁剪对应的数据区域。比如在一个10*10的矩阵中,上面的四个数字(0.6,0.8 ;0.1,0.3)对应的区域如图1中的绿色区域

       

                                                                                     图1 示例图

3)数据保存

geotiffwrite(filename,A,R) writes a georeferenced image or data grid, A, spatially referenced by R, into an output file, filename.

操作与读取类似,不再赘述!

二、例子

                                                                                        图2 原始数据

 

                                                   

                                                                             图3 原始数据地理坐标信息

 

                                               

                                                                            图4 截取之后的地理坐标信息

1Code


 
 
  1. function Geographic_RPW()
  2. tic %Record the running time
  3. %% Read file
  4. [Data,R] = geotiffread( 'D:\20181102\CSDN-博文\Matlab处理地理数据\ndvi2.tif');
  5. %% Select interception position
  6. Start_Latitude = 0.6;
  7. End_Latitude = 0.8;
  8. Start_Lontitude = 0.1;
  9. End_Lontitude = 0.3;
  10. %需要补充一下此四个数的意义
  11. %% cuttiing into certain shape
  12. Posion = [Start_Latitude,End_Latitude;Start_Lontitude,End_Lontitude];
  13. [row, col] = size(Data);
  14. first_row = floor(Posion( 1, 1)*row)+ 1;%起始维度(加 1为了避免first_row= 0,使用ceil函数可以不用加 1)
  15. last_row = floor(Posion( 1, 2)*row);%结束维度
  16. first_col = floor(Posion( 2, 1)*col)+ 1;%起始经度(加 1为了避免first_row= 0,使用ceil函数可以不用加 1)
  17. last_col = floor(Posion( 2, 2)*col);%结束经度
  18. subImage = Data(first_row:last_row, first_col:last_col);%数据截取
  19. %% Set GeographicCells Reference parameters
  20. %文件的地理坐标信息还有样本大小信息同样也是需要截取的和更新的,截取的基本理论类似与数据的截取办法。
  21. % mainly set the range of latitude and lontitude
  22. subR = R;%原始数据的地理坐标信息和数据大小等信息。
  23. subR.RasterSize = size(subImage);%跟新截取后的数据大小信息
  24. del_La = subR.LatitudeLimits( 2) - subR.LatitudeLimits( 1);% the scale of latitude(纬度的最大值减去最小值)
  25. del_Lon = subR.LongitudeLimits( 2) - subR.LongitudeLimits( 1);% the scale of lontitude(经度的最大值减去最小值)
  26. subR.LatitudeLimits = [subR.LatitudeLimits( 1)+Posion( 1, 1)*del_La,...
  27. subR.LatitudeLimits( 2) - del_La*( 1 - Posion( 1, 2))];%截取位置的维度范围
  28. subR.LongitudeLimits = [subR.LongitudeLimits( 1)+Posion( 2, 1)*del_Lon,...
  29. subR.LongitudeLimits( 2) - del_Lon*( 1 - Posion( 2, 2))];%截取位置的经度范围
  30. %% Data processing
  31. %一些最基本的数据处理,在此要根据数据的性质(大小与分布规律看一下)
  32. %在matlab调试中看一下截取后的数据的值,下面这个处理过程只是针对我
  33. %所要解决的一个问题。
  34. [row,col] = size(subImage);
  35. for i = 1:row
  36. for j = 1:col
  37. if subImage(i,j)< 0
  38. subImage(i,j) = 0;
  39. elseif subImage(i,j)> 0
  40. subImage(i,j) = 1;
  41. end
  42. end
  43. end
  44. for i = floor( 0.45*row):floor( 0.8*row)
  45. for j = floor( 0.14*col):floor( 0.5*col)
  46. if subImage(i,j)<= 0
  47. subImage(i,j) = 0;
  48. elseif subImage(i,j)> 0
  49. subImage(i,j) = 2;
  50. end
  51. end
  52. end
  53. %% Preview the interception posion
  54. figure( 1);
  55. imshow(subImage);%黑白图
  56. figure( 2);
  57. imagesc(subImage);%彩色图
  58. %% Writiing the data to a new GEOTIFF file
  59. filename = 'C:\Users\Administrator\Desktop\ndvi-new.tif';
  60. geotiffwrite(filename,subImage,subR);%保存文件
  61. toc%Recording the time when the program end running
  62. %% Writed By themingyi
  63. % 2018/ 12/ 05

2)处理结果

                   

 

                                                                                             图5 imshow展示结果

 

                       

                                                                                             图6 imagesc 展示结果

 

                                

                                                                                          图7 AI修改后的最终结果

 

PS:本程序以及所有使用的数据已经放到百度云供下载:

链接:https://pan.baidu.com/s/1o2vC_1QKyWmwvW8-g-E09Q 
提取码:s97g 
欢迎讨论指正,本人e-mail:themingyi123@gmail.com

 

参考:

1、https://www.mathworks.com/help/map/ref/geotiffread.html

2、https://blog.csdn.net/liyanzhong/article/details/52850581

Matlab读取带有地理信息的图像

3、http://www.ilovematlab.cn/forum.php?mod=viewthread&tid=213403

MATLAB 遥感影像的读写操作,带地理坐标信息

4、https://blog.csdn.net/qq_26906835/article/details/80841823

Matlab(一):二维矩阵转换为geoTiff

5、http://www.mathworks.com/help/map/ref/geotiffwrite.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值