桃之夭夭分享 http://blog.sciencenet.cn/u/yelloworld

博文

IDL_Code图像减法

已有 2733 次阅读 2012-3-22 10:18 |个人分类:IDL|系统分类:科研笔记| BandSubstract

;*******************************************************************************
;*Usage: to calculate the substration between two multi-bands images.          *
;*******************************************************************************
;*Parameters:                                                                  *
;*BandSubstract,img1,img2,data_type,outimg                                     *
;* img1: the subtrahend image                                                  *
;* img2: the minuend image
;* data_type: a label is used to declare if the data_type of the images    *
;*            are byte format.                                                 *
;* out_img: the result for output.                                             *
;*******************************************************************************   
pro BandSubstract,img1,img2,data_type,outimg
;*to check if we can open the two images
 envi_open_file,img1,r_fid=fid1
 if fid1 eq -1 then begin
     message,'Cannot open file '+img1
 endif
 envi_open_file,img2,r_fid=fid2
 if fid2 eq -1 then begin
     message,'Cannot open file '+img2
 endif
 ;*to query the size parameters
 envi_file_query,fid1,ns=ns,nl=nl,nb=nb
 ;*to create an new images for output
 openw,lun,outimg,/get_lun
 dims=[-1,0,ns-1,0,nl-1]
 ;*make a substracting calculation band by band
 for i=0,nb-1 do begin
     data1=envi_get_data(fid=fid1,dims=dims,pos=i)
     data2=envi_get_data(fid=fid2,dims=dims,pos=i)
     if data_type eq 1 then begin
         out=int(data2)-int(data1)
     endif
     if data_type eq 1 then begin
          out=data2-data1
      endif
     writeu,lun,out
 endfor
 close,lun
 free_lun,lun
 envi_setup_head,fname=outimg,ns=ns,nl=nl,nb=nb,data_type=2,$
          interleave=0,offset=0, /write,/open
end


https://blog.sciencenet.cn/blog-219445-550465.html

上一篇:IDL_Code_根据两个TXT文档的关键字列进行合并
下一篇:WMO气象区位台站命名规则
收藏 IP: 202.99.63.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-25 01:11

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部