function resize_shp,shpfile,infile,outfile
compile_opt idl2
envi,/restore_base_save_files
envi_batch_init,log_file = 'log.txt'
envi_open_file,infile,r_fid = fid
if fid eq -1 then begin
envi_batch_exit
return,0
endif
envi_file_query,fid,nb = nb,bnames = bnames
pos = lindgen(nb)
oshp = obj_new('IDLffShape',shpfile)
oshp ->getproperty,N_ENTITIES=num_ent
; ,$
; ATTRIBUTE_INFO = attr_info,N_ATTRIBUTES = n_attr,$
; ENTITY_TYPE = ent_type
;讀坐標(biāo),并存在相應(yīng)的數(shù)組中
minx = dblarr(num_ent)
maxx = dblarr(num_ent)
miny = dblarr(num_ent)
maxy = dblarr(num_ent)
for i = 0,num_ent - 1 do begin
ent = oshp->getentity(i)
minx[i] = ent.bounds[0]
miny[i] = ent.bounds[1]
maxx[i] = ent.bounds[4]
maxy[i] = ent.bounds[5]
endfor
OBJ_DESTROY,oshp ;銷毀一個(gè)shape對(duì)象
;求整個(gè)shp的邊界
minvalue_x = min(minx);最大x值
maxvalue_x = max(maxx);最大x值
minvalue_y = min(miny);最小y值
maxvalue_y = max(maxy);最小y值
;用這個(gè)范圍對(duì)圖像進(jìn)行裁剪
xmap = [minvalue_x,maxvalue_x]
ymap = [minvalue_y,maxvalue_y]
envi_convert_file_coordinates,fid,xf,yf,xmap,ymap
dims = [-1,long(xf[0]),long(xf[1]),long(yf[1]),long(yf[0])]
; out_name = 'E:\text\evf_roi\a.raw'
envi_doit,'RESIZE_DOIT',fid = fid,dims = dims,$
out_name = outfile,$
pos = pos,out_bname = bnames,$
r_fid = resized_fid,rfact = [1.0,1.0]
end
要是可以實(shí)現(xiàn)不規(guī)則裁剪就好了,再琢磨琢磨?。?!