;-------------------------------------------------------------- ;Motivation: ; cheking and fixing the invalid pixels ;Input: ; InputPath-end with '\' ; InputName ; Outpath ;Output: ; new file of wich the invalid pixels are fixed ; the new filename is suffixed with '_IvdPxl' after the origin filename ;Created by ShuaiTong 2011.06.09 ; ;-------------------------------------------------------------- pro InvalidPixel,InputPath,InputName,OutPath ;Input ; InputPath='D:\results\moon\Copernicus\' ; InputName='CE1_BMYK_IIM_XXX_2874_B_reflectance_correct_validB_MNF_IvdLine.img'; ; OutPath=InputPath OutName=file_basename(InputName,'.img')+'_IvdPxl.img' file=InputPath+InputName tp=2;max threshold for invalid pixel; tp=2 ;open file ENVI_OPEN_FILE,file,r_fid=fid ENVI_FILE_QUERY,fid,ns=ns,nl=nl,nb=nb,dims=dims band=fltarr(ns,nl);存放波段数组 bGrads=fltarr(ns,nl);存放梯度 bGrads1=fltarr(ns,nl);存放梯度分子 bGrads2=fltarr(ns,nl);存放梯度分母 bandNew=fltarr(ns,nl,nb);存放修复后的数据 for b=0,nb-1 do begin band=ENVI_GET_DATA(fid=fid,dims=dims,pos=b) bandNew[*,*,b]=band ;computing grads for s=1,ns-2 do begin bGrads1[s,*]=band[s-1,*]+band[s+1,*]-2*band[s,*] bGrads2[s,*]=band[s-1,*]+band[s+1,*] endfor for l=1,nl-2 do begin bGrads1[*,l]=bGrads1[*,l]+band[*,l-1]+band[*,l+1]-2*band[*,l] bGrads2[*,l]=bGrads2[*,l]+band[*,l-1]+band[*,l+1] endfor bGrads[1:ns-2,1:nl-2]=abs(bGrads1[1:ns-2,1:nl-2]/bGrads2[1:ns-2,1:nl-2]*4) ; print,bGrads[*,636] ;Invalid pixels locations index=where(bGrads gt tp,count) ; print,'band',b+1,',',count,' invalid pixels' linePositon=where(bGrads gt tp)/ns samplePosition=where(bGrads gt tp) mod ns ; print,'line ',linePositon ; print,'sample',samplePosition ; Fixing invalid pixels for icount=0,count-1 do begin lp=linePositon[icount] sp=samplePosition[icount] bandNew[sp,lp,b]=(bandNew[sp+1,lp,b] + bandNew[sp-1,lp,b] + bandNew[sp,lp+1,b] + bandNew[sp,lp-1,b])/4 ; print,'fix pixel:line',lp,',sample',sp endfor ; print,'--------------------------------------------------' endfor ;output file ENVI_WRITE_ENVI_FILE, bandNew, out_name=OutPath+OutName,r_fid=r_fid print, OutPath, OutName, '. is over!' envi_file_mng, id=fid, /remove; , /delete envi_file_mng, id=r_fid, /remove end