首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用IDL和ENVI在批处理模式下对图像进行空间子集

使用IDL和ENVI在批处理模式下对图像进行空间子集
EN

Stack Overflow用户
提问于 2012-07-26 02:49:39
回答 1查看 3K关注 0票数 0

我想使用IDL程序在ENVI中对陆地卫星照片进行空间子集。我有超过150个图像,我想要子集,所以我想在批处理模式下运行程序(没有交互)。我知道如何手动操作,但我将使用什么命令通过IDL代码中的经纬度坐标对图像进行空间子集?

EN

回答 1

Stack Overflow用户

发布于 2012-09-30 17:21:01

这里有一些关于单个文件的灵感。您可以通过构建文件名列表并在其上循环,对大量文件执行相同的操作。

代码语言:javascript
复制
; define the image to be opened (could be in a loop), I believe it can also be a tif, img...
img_file='path/to/image.hdr'
envi_open_file,img_file,r_fid=fid
if (fid eq -1) then begin
    print, 'Error when opening file ',img_file
    return
  endif

; let's define some coordinates
XMap=[-70.0580916, -70.5006694]
YMap=[-32.6030694, -32.9797194]
; now convert coordinates into pixel position:
; the transformation function uses the image geographic information:
ENVI_CONVERT_FILE_COORDINATES, FID, XF, YF, XMap, YMap
; we must consider integer. Think twice here, maybe you need to floor() or ceil()
XF=ROUND(XF)
YF=ROUND(YF)

; read the image
envi_file_query, fid, DIMS=DIMS, NB=NB, NL=NL, NS=NS
pos  = lindgen(nb)
; and store it in an array
image=fltarr(NS, NL, NB)
; read each band sequentially
FOR i=0, NB-1 DO BEGIN
   image[*,*,i]= envi_get_data(fid=fid, dims=dims, pos=pos[i])
endfor

; simply crop the data with array-indexing function
imagen= image[XF[0]:XF[1],YF[0]:YF[1]]

nl2=YF[1]-YF[0]
ns2=XF[1]-XF[0]

; read mapinfo to save it in the final file
map_info=envi_get_map_info(fid=fid)

envi_write_envi_file, imagen, data_type=4, $
  descrip = 'cropped', $
  map_info = map_info, $
  nl=nl2, ns=ns2, nb=nb, r_fid=r_fid, $
  OUT_NAME = 'path/to/cropped.hdr'
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11656573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档