需求:需要对tiff格式的sar遥感图像进行检测,因此通过matlab进行预处理,将tiff格式转化为jpg格式,并且提取其中的经纬度信息到txt中。最后将检测完毕的图像写回遥感图像。

实现:利用matlab完成

1.tiffToJPG.m 作用:将tiff转为jpg并提取信息到txt

%This function is used to extract remote sensing image information into a
%text file,and get a jpg type img from tiff remote sensing image.
%author:maqy 2017.09.05
%param:
% geoTiffpath:the path of geotiff img.
% jpgOutPath: the path of output jpg img.
% txtInfoOutPath:the path of output txt file.
function tiffToJPG(geoTiffPath,jpgOutPath,txtInfoOutPath)%filename='/home/hadoop/DocumentMaqy/test.tiff';  the path of geotiff img.
%outpath='/home/hadoop/DocumentMaqy/a.jpg';    the path of output jpg img.
%'/home/hadoop/DocumentMaqy/a.txt'  the path of output txt file.
filename=geoTiffPath;
out=jpgOutPath;
txtpath=txtInfoOutPath;
[I,R]=geotiffread(filename);%I is the normal img and R is the geo information.
info=geotiffinfo(filename);
I=uint8(I);%The default format of the photo is 16 bit, translate it to 8 bit.
imwrite(I,out,'jpg');
fid = fopen(txtpath,'w');
%fprintf(fid,'%s\n',info.FileModDate);
fprintf(fid,'%f\n',info.CornerCoords.Lat);
fprintf(fid,'%f\n',info.CornerCoords.Lon);
fclose(fid);

2.tiffToJPGDir.m 作用:一次处理一个文件夹

%Convert remote sensing images in a folder.
%author:maqy 2017.09.06
%param:
% geoTiffpath:the path of geotiff img.
% jpgOutPath: the path of output jpg img.
% txtInfoOutPath:the path of output txt file.function tiffToJPGDir(geoTiffPath,jpgOutPath,txtInfoOutPath)
Files = dir(fullfile(geoTiffPath,'*.tiff'));LengthFiles = length(Files);for i = 1:LengthFilesfilename = strcat(geoTiffPath,Files(i).name);tmp=Files(i).name;% such as 1.tifftmp(end-4:end)=[];% get name without format '.tiff'out=strcat(tmp,'.jpg');% such as 1.jpgout=strcat(jpgOutPath,out);% concat /jpgOutPath/1.jpgtxtpath=strcat(tmp,'_info.txt');% get 1_info.txttxtpath=strcat(txtInfoOutPath,txtpath);% get /txtInfoOutPath/1_info.txt[I,R]=geotiffread(filename);info=geotiffinfo(filename);I=uint8(I);imwrite(I,out,'jpg');fid = fopen(txtpath,'w');%fprintf(fid,'%s\n',info.FileModDate);  this line used to%output Date information to txtfprintf(fid,'%f\n',info.CornerCoords.Lat);fprintf(fid,'%f\n',info.CornerCoords.Lon);fclose(fid);end

3.writeBackToTiff.m 作用:将检测完毕的jpg图像写回tiff

%write the detected ship jpg img back to tiff
%author:maqy 2017.09.07
%param:
% geoTiffInPath:the path of geotiff img.
% detectedImgPath: the detected ship img
% geoTiffOutPath:the path of output geotiff file.
function writeBackToTiff(geoTiffInPath,detectedImgPath,geoTiffOutPath)
filename=geoTiffInPath;
out=geoTiffOutPath;
[~,R]=geotiffread(filename);
info=geotiffinfo(filename);
img=imread(detectedImgPath);
%imshow(T);
img_size=size(img);
dimension=numel(img_size);
if dimension>2img=rgb2gray(img);
end
geotiffwrite(out, img, R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);

4.writeBackToTiffTrans.m 作用:在3的基础上,去除黑边,并修改一下存储的文件信息

%write the detected ship jpg img back to tiff,and remove the black edges in
%the tif.
%author:maqy 2017.10.07
%param:
% geoTiffInPath:the path of geotiff img.
% detectedImgPath: the detected ship img
% geoTiffOutPath:the path of output geotiff file. attention: this param
% can't end with '.tiff'.
function writeBackToTiffTrans(geoTiffInPath,detectedImgPath,geoTiffOutPath)
filename=geoTiffInPath;
out=geoTiffOutPath;
[I,R]=geotiffread(filename);%get tiff img
info=geotiffinfo(filename);%test
%info.GeoTIFFTags.GeoKeyDirectoryTag.GTCitationGeoKey='GCS_WGS_1984';
%info.GeoTIFFTags.GeoKeyDirectoryTag.GeogCitationGeoKey='';s1=info.GeoTIFFTags.GeoKeyDirectoryTag;
s2=struct('GTModelTypeGeoKey',s1.GTModelTypeGeoKey,...'GTRasterTypeGeoKey',s1.GTRasterTypeGeoKey,...'GeographicTypeGeoKey',s1.GeographicTypeGeoKey,...'GTCitationGeoKey','WGS84 / Google Mercator',...'GeogEllipsoidGeoKey',s1.GeogEllipsoidGeoKey,...'GeogSemiMajorAxisGeoKey',s1.GeogSemiMajorAxisGeoKey,...'GeogSemiMinorAxisGeoKey',s1.GeogSemiMinorAxisGeoKey,...'ProjectedCSTypeGeoKey',s1.ProjectedCSTypeGeoKey,...'ProjectionGeoKey',s1.ProjectionGeoKey,...'ProjCoordTransGeoKey',s1.ProjCoordTransGeoKey,...'ProjLinearUnitsGeoKey',s1.ProjLinearUnitsGeoKey,...'ProjNatOriginLongGeoKey',s1.ProjNatOriginLongGeoKey,...'ProjNatOriginLatGeoKey',s1.ProjNatOriginLatGeoKey,...'ProjFalseEastingGeoKey',s1.ProjFalseEastingGeoKey,...'ProjFalseNorthingGeoKey',s1.ProjFalseNorthingGeoKey,...'ProjScaleAtNatOriginGeoKey',s1.ProjScaleAtNatOriginGeoKey);img=imread(detectedImgPath); %get detected img%if the img has more than one channel, convert to gray.
img_size=size(img);
dimension=numel(img_size);
if dimension>2img=rgb2gray(img);
end%get the Alpha matrix
[dim1,dim2]=size(I);
Alpha=255*ones(dim1,dim2);
for i=1:dim1for j=1:dim2if(I(i,j)==0)Alpha(i,j)=0;endend
end
%imshow(T);%set result
result=ones(dim1,dim2,2);
result(:,:,1)=img(:,:,1);
result(:,:,2)=Alpha(:,:,1);
result=uint8(result);%geotiffwrite(out, result, R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
geotiffwrite(out, result, R,'GeoKeyDirectoryTag',s2);

PS:可以将其打成jar包利用java来调用,参考:
https://blog.csdn.net/cs_fang_dn/article/details/50239115

利用matlab处理tiff格式的遥感图像相关推荐

  1. matlab segy文件,利用matlab实现segy格式数据的读写研究和分析.ppt

    利用matlab实现segy格式数据的读写研究和分析 2.SEGY数据格式 地震数据一般以地震道为单位进行组织,采用SEG-Y文件格式存储.SEG-Y格式是由SEG (Society of Explo ...

  2. 利用matlab将.mat格式文件转换成wav文件

    利用matlab将.mat格式文件转换成wav文件 clc; clear all; clear all;filenames = dir('f16.mat') n = numel(filenames)f ...

  3. 如何利用Matlab对Comtrade99格式的故障录波文件进行数据读取

    如何利用Matlab对Comtrade99格式的故障录波文件进行数据读取 近来看了几个采用Matlab对标准故障录波数据进行读取的例子,自己参照着动手实践了下,发现有些问题,现在记录下来以备大家参考. ...

  4. Matlab读写TIFF格式文件

    1.简介 通常情况下,使用MATLAB做图像处理后,使用下面的命令就可以保存处理结果为图片. imwrite(im,'im.bmp'); 而如果需要保存的图像为single或者double类型,或保存 ...

  5. 转Matlab读写TIFF格式文件

    1.简介 通常情况下,使用MATLAB做图像处理后,使用下面的命令就可以保存处理结果为图片. imwrite(im,'im.bmp'); 而如果需要保存的图像为single或者double类型,或保存 ...

  6. Matlab写TIFF格式文件(多于3波段)

    1.起因 通常情况下,使用MATLAB做图像处理后,使用下面的命令就可以保存处理结果为图片. imwrite(im,'im.bmp'); 而如果需要保存的图像为single或者double类型,或保存 ...

  7. matlab中pct使用,如何利用Matlab读取PCT格式的图像文件

    图像文件有多种多样,我们常见的有jpg.tif.png.bmp等等,这些格式利用Matlab中的imread均可以完成读取的工作,但是还有一些少见的格式,如pct格式的图像文件,在Matlab中直接利 ...

  8. Matlab 读取欧空局*.N1卫星遥感图像

    卫星遥感图像往往具有复杂的数据格式,其文件当中既包含了字符串,又包含了图像信息,如果采用直接打开文件的方式,很可能读取到的都是乱码,因此要分步读取文件内容,并对数据进行加工处理. 作者目前了解到遥感数 ...

  9. tif文件转为shp文件_在arcgis中怎么把tif格式的遥感图像转换为矢量图

    http://bbs.3s001.com/thread-67153-1-1.html,这个帖子里有讲操作步骤 一.对影像的校准和配准 1.打开ArcMap,增加Georeferncing工具条. 2. ...

最新文章

  1. 河南城建学院计算机分数,河南城建学院录取分数线2021是多少分(附历年录取分数线)...
  2. centos安装软件_CentOS 8 和 Ubuntu 18.04 部分软件版本比较
  3. jsp实现数据禁用和只读
  4. 关于visio你必须要知道的一些小技巧
  5. CentOS下编译安装Gcc-4.9
  6. 服务监管框架下的 IT 运维服务与绩效管理体系建设
  7. freeswitch+kamailio+unimrcp
  8. 运动控制器的自定义G代码编程应用
  9. nba篮球大师服务器维护,NBA篮球大师怎么进不去 NBA篮球大师黑屏闪退解决方法...
  10. matlab代码 布谷鸟优化算法CS原代码, 包含23个基准测试函数,都可运行
  11. 爬虫和网易云音乐API的一次尝试
  12. android 画三角形
  13. Python多线程-手慢无的真相
  14. 训练集样本不平衡问题对深度学习的影响
  15. besides、but、except、except for、except that和except when
  16. Python计算机视觉编程(二)---SIFT、Harris特征
  17. mysql解决中文乱码问题
  18. 截流式合流制设计流量计算_[2018年最新整理]合流制排水管网设计与计算.ppt
  19. sendmail 电子邮件服务器
  20. 李嘉诚传给年青人的53条人生忠告

热门文章

  1. 全系列MTK monitor芯片需求
  2. linux局域网连接网络打印机驱动,柯尼卡美能达网络打印驱动程序安装方法
  3. 酒浓码浓 - nginx常用配置
  4. linux可视化管理工具-旗鱼云梯
  5. 牛!Mathematica还能这样用!自己制作马赛克拼图
  6. 7-4 美女排名 (15分)
  7. 孔雀石SDR入手体验
  8. 集算器入门之安装与基本使用
  9. GoWithMi,一个可以买卖地块资源的分布式地图生态
  10. 人性的弱点【卡耐基】