使用IDL和ENVI以批处理模式空间子集图像

时间:2012-07-25 18:49:39

标签: subset spatial idl idl-programming-language envi

我想使用IDL程序在ENVI中空间分配LANDSAT照片。我有超过150个图像,我想要分组,所以我想以批处理模式运行程序(没有交互)。我知道如何手动完成,但是我会使用什么命令通过IDL代码中的lat / long坐标对图像进行空间子集化?

1 个答案:

答案 0 :(得分:2)

对于单个文件,这是一些灵感。 您可以通过构建来为大量文件执行相同的操作 一个文件名列表并循环遍历它。

; 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'