2010年10月23日土曜日

IDL——求图像熵

pro calc_entropy   ;   ; Open a data file   ;   fname = 'G:\Program Files\ITT\IDL70\products\envi45\data\bhtmref.img'   envi_open_data_file, fname, r_fid=fid   if (fid eq -1) then begin     print,'can not open!!!!!!'     return   endif    starttime=systime(/seconds);³ÌÐò¿ªÊ¼    envi_file_query, fid, dims=dims, nb=nb   entropyArr = dblarr(nb)    for itr=0,nb-1,1 do begin     data = ENVI_GET_DATA(fid=fid, dims=dims, pos=itr)     S=size(data)     nall=S[4]     ;print,'size=',s     ;print,nx,'cols *',ny,'rows'      n=double(nall)     max1=max(data[*,*])     min1=min(data[*,*])     s=0.0D     for i=min1,max1,1 do begin       a=where(data[*,*] eq i,num)       if num ne 0 then begin         p=num/n         s=s+p*(alog(p)/alog(2))       endif     endfor     s=-s     entropyArr[itr]=s   endfor    endtime=systime(/seconds)   print,endtime-starttime   print,entropyArr end

0 件のコメント: