`
mywebcode
  • 浏览: 998112 次
文章分类
社区版块
存档分类
最新评论

信息熵的计算心得

 
阅读更多
对于信息熵的计算,可能相关算法很多,具体的在idl中如何实现,就着前段时间朋友的帮助将自己的心得分享给大家,希望对大家学习idl有所帮助。

;;在编写代码的过程中有需要注意的几点:1)idl如何读取img格式的数据文件(除去通用格式数据意外),如何调用envi函数?2)整体的编程思路是怎样的?3)分析结果的保存。

pro articulation

COMPILE_OPT idl2
ENVI, /restore_base_save_files
envi_batch_init
infile = dialog_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 ,INTERP=INTERP

pos = lindgen(nb)
print,pos
data = ENVI_GET_DATA(/COMPLEX, DIMS=dims, FID=fid , INTERP=INTERP, POS=pos)
help,data
file_size = size(data)
print,file_size
column = file_size[1]
row = file_size[2]
data_new = make_array(column,row,nb)


DNmax = max(data)
DNmin = min(data)
print,DNmax
;
;;信息熵的计算
;
new_data = make_array(DNmax)

for i = DNmin,DNmax-1 do begin
index = where((data-i) ne 0,count)
if count eq 0 then begin
P = 0
endif else begin
P = count/float((row*column))
endelse
new_data[i] = P * (alog10(P) /alog10(2))
; print,new_data[i]
endfor
outdata = - total(new_data)
; print,outdata

;
outfile = dialog_pickfile(title = '保存结果到TXT文档:',filter = '*.txt')
openw,lun,outfile,/get_lun

printf,lun,'信息熵:',outdata
free_lun,lun

end


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics