LearningENVI&IDL分享 http://blog.sciencenet.cn/u/dongyanqing Learning ENVI&IDL

博文

ENVI下将图像各波段单独存为文件的解决与分析测试

已有 8273 次阅读 2012-1-10 09:39 |个人分类:ENVI|系统分类:科研笔记| ENVI, 二次开发, 存文件

论坛里面的一个问题“ENVI怎样将图像各波段分开为单独文件”。IDL二次开发调用ENVI函数可以轻松实现,用哪个函数呢,有 “cf_doit”、“resize_doit”、“math_doit”、“envi_layer_stacking_doit”等几个。当然了,将各波段一次全部读出来再写成二进制文件也行(分块也可以,稍微麻烦些),一旦遇到大数据了不好控制内存占用。
基于:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=60383 对上面几种方式的调用和花费时间简单进行了测试,程序主界面如下:

sav程序http://www.rayfile.com/files/7cb9e3de-3b25-11e1-91d0-0015c55db73d/ 主要功能代码如下:

   

      FOR i=0,N_ELEMENTS(files)-1 DO BEGIN

        ;构建输出文件名

        fileName = FILE_BASENAME(files[i])

        pointPos = STRPOS(fileName,'.')

        ;查找文件名中点的位置

        IF pointPos[0] NE -1 THEN BEGIN

          fileName= STRMID(fileName,0,pointPos)

        ENDIF

       

       

        ENVI_OPEN_FILE, files[i], r_fid=fid

        IF (fid EQ -1) THEN BEGIN

          tmp = DIALOG_MESSAGE(files[i]+'文件读取错误',$

            title = !sys_title, /error)

          CONTINUE

        ENDIF

        ;文件信息

        ENVI_FILE_QUERY, fid, dims=dims, nb=nb,bnames = bnames,DATA_TYPE = dt,$

          ns = ns, nl = nl

        startTime = systime(1)

        for curBand =0,nb-1 do begin

          out_name = outfiledir+PATH_SEP()+fileName+'_band'+StrTrim(curBand+1,2)+'.img'

          envi_doit, 'cf_doit', $

            fid=fid, pos=curBand, dims=dims, $

            remove=0, out_name=out_name

        endfor

        ;

        print,'cf_doit time',systime(1)-startTime

        startTime = systime(1)

        for curBand =0,nb-1 do begin

          out_name = outfiledir+PATH_SEP()+fileName+'_band_resize'+StrTrim(curBand+1,2)+'.img'

          envi_doit, 'resize_doit', $

            fid=fid, pos=curBand, dims=dims, $

            interp=1, rfact=[1,1], $

            out_name=out_name

        endfor

        print,'resize_doit time',systime(1)-startTime

       

       

        startTime = systime(1)

        for curBand =0,nb-1 do begin

          out_name = outfiledir+PATH_SEP()+fileName+'_band_bandmath'+StrTrim(curBand+1,2)+'.img'

          pos  = curBand

          exp = 'b1'

          envi_doit, 'math_doit', $

            fid=fid, pos=pos, dims=dims, $

            exp=exp, out_name=out_name

        endfor

        print,'math_doit time',systime(1)-startTime

       

        startTime = systime(1)

        for curBand =0,nb-1 do begin

       

          pos  = curBand

          out_proj = envi_get_projection(fid=fid, $

            pixel_size=out_ps)

          out_name = outfiledir+PATH_SEP()+fileName+'_layer_stacking'+StrTrim(curBand+1,2)+'.img'

          envi_doit, 'envi_layer_stacking_doit', $

            fid=fid, pos=pos, dims=dims, $

            out_dt=dt, out_name=out_name, $

            interp=2, out_ps=out_ps, $

            out_proj=out_proj

        endfor

        print,'layer_stacking_doit time',systime(1)-startTime

        ;依次读写文件

        startTime = systime(1)

        for curBand =0,nb-1 do begin

       

          pos  = curBand

          map_info = envi_get_map_info(fid=fid) 

          out_name = outfiledir+PATH_SEP()+fileName+'_writeu'+StrTrim(curBand+1,2)+'.img'

          openw,lun,out_name,/get

          writeu,lun,envi_get_data(fid=fid, dims=dims, pos=pos)

          free_lun,lun

          ENVI_SETUP_HEAD, fname=out_name, $

          ns=ns, nl=nl, nb=1, $

          interleave=0, data_type=dt, $

          offset=0, /write,$

          MAP_INFO = MAP_INFO

        endfor

        print,'writeU time',systime(1)-startTime

       

        ;输出完成

        ENVI_FILE_MNG, id=fid, /remove

        ;设置进度条

        IDLITWDPROGRESSBAR_SETVALUE,(*pState).PRSBAR,(i+1)*per

      ENDFOR


70M左右的224个波段的高光谱数据测试,各方法花费的时间如下:

cf_doit time       2.5090001

resize_doit time       3.3580000

math_doit time       3.5969999

layer_stacking_doit time       8.9680002

writeU time       2.2889998
这里的writeU最快,cf_doit次之,也在意料之中,因其他函数均支持分块处理。故最保险的函数还是选用cf_doit

https://wap.sciencenet.cn/blog-344887-527568.html

上一篇:2011年12月的IDL程序开发、ENVI二次开发和混编开发视频专辑
下一篇:IDL DICOM扩展模块
收藏 IP: 124.205.245.*| 热度|

0

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

数据加载中...

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

GMT+8, 2024-3-28 23:55

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部