发表这篇文章主要是想给大家介绍一下3*3窗口的遍历运算过程,希望对大家所有帮助!
PRO Information
COMPILE_OPT idl2
ENVI, /restore_base_save_files
envi_batch_init
infile = ENVI_PICKFILE(title = '请选择要打开的文件:')
ENVI_OPEN_FILE, infile, r_fid=fid
IF (fid EQ -1) THEN BEGIN
ENVI_BATCH_EXIT
RETURN
ENDIF
ENVI_FILE_QUERY, fid, dims=dims, nb=nb ,nl=nl,ns=ns
pos = LINDGEN(nb)
; proj = ENVI_GET_PROJECTION(FID = fid,pixel_size=Dx)
Dx = 1
; print,Dx
; data = indgen(nl,ns)
;
;;清晰度的计算
;
FOR g=0,nb-1 DO BEGIN
data = ENVI_GET_DATA(DIMS=dims, FID=fid , POS=g)
new_data = make_array(ns,nl)
HELP,data
Den = nl*ns
; print,Den
;ns&nl写反了
FOR i = 1,ns-2 DO BEGIN
FOR j = 1,nl-2 DO BEGIN
;获取一个3*3的窗口
t= data[[i-1]:[i+1],[j-1]:[j+1]]
; help,t
;对每个窗口做计算
d1=ABS((t[0,0]-t[1,1])/(Dx*1.414))
d2=ABS(t[0,1]-t[1,1])/(Dx*1.0)
d3=ABS(t[0,2]-t[1,1])/(Dx*1.414)
d4=ABS(t[1,0]-t[1,1])/(Dx*1.0)
d5=ABS(t[1,2]-t[1,1])/(Dx*1.0)
d6=ABS(t[2,0]-t[1,1])/(Dx*1.414)
d7=ABS(t[2,1]-t[1,1])/(Dx*1.0)
d8=ABS(t[2,2]-t[1,1])/(Dx*1.414)
;计算每个窗口的df/dx
new_data[i,j]=d1+d2+d3+d4+d5+d6+d7+d8
ENDFOR
ENDFOR
dd = total(new_data)
; print,dd
utdata = (dd/Den)/1000
print,outdata
;
;;保存文件
;
utfile = infile+'_band'+StrTrim(g,2)+'.txt'
; utfile = dialog_pickfile(title = '保存结果到TXT文档:',filter = '*.txt')
print,outfile
openw,lun,outfile,/get_lun
printf,lun,'清晰度:',outdata
free_lun,lun
ENDFOR
END