;******************************************************************************* ;*Usage: to calculate the substration between two multi-bands images. * ;******************************************************************************* ;*Parameters: * ;*BandSubstract,img1,img2,data_type,outimg * ;* img1: the subtrahend image * ;* img2: the minuend image ;* data_type: a label is used to declare if the data_type of the images * ;* are byte format. * ;* out_img: the result for output. * ;*******************************************************************************
pro BandSubstract,img1,img2,data_type,outimg ;*to check if we can open the two images envi_open_file,img1,r_fid=fid1 if fid1 eq -1 then begin message,'Cannot open file '+img1 endif envi_open_file,img2,r_fid=fid2 if fid2 eq -1 then begin message,'Cannot open file '+img2 endif ;*to query the size parameters envi_file_query,fid1,ns=ns,nl=nl,nb=nb ;*to create an new images for output openw,lun,outimg,/get_lun dims=[-1,0,ns-1,0,nl-1] ;*make a substracting calculation band by band for i=0,nb-1 do begin data1=envi_get_data(fid=fid1,dims=dims,pos=i) data2=envi_get_data(fid=fid2,dims=dims,pos=i) if data_type eq 1 then begin out=int(data2)-int(data1) endif if data_type eq 1 then begin out=data2-data1 endif writeu,lun,out endfor close,lun free_lun,lun envi_setup_head,fname=outimg,ns=ns,nl=nl,nb=nb,data_type=2,$ interleave=0,offset=0, /write,/open end