IDL实现遥感影像的监督分类

利用IDL实现对遥感影像的最大似然的监督分类

pro classfication
COMPILE_OPT IDL2
ENVI,/restore_base_files
;进行最大似然法分类
file=‘D:\0\classfication_img.dat’
out_file=‘D:\0\classfication_maxlikehood’
envi_open_file,file,r_fid=fid
envi_file_query,fid,ns=ns,bl=nl,nb=nb,dims=dims
pos=indgen(nb)
;读入roi文件
file_roi=‘D:\0\roi_1.roi’
envi_restore_rois,file_roi
roi_ids=envi_get_roi_ids(fid=fid,roi_colors=roi_colors,roi_names=class_names)
class_names=[‘Unclassfication’,class_names];增加一个未
num_classes=n_elements(roi_ids)
lookup=bytarr(3,num_classes+1)
lookup[,1:num_classes]=roi_colors;各个类别的颜色数组
means=fltarr(nb,num_classes)
stdv=fltarr(nb,num_classes)
cov=fltarr(nb,nb,num_classes)
for j=0,num_classes-1 do begin
roi_dims=[envi_get_roi_dims_ptr(roi_ids[j]),0,0,0,0]
print,roi_dims
envi_doit,‘envi_stats_doit’,fid=fid,dims=roi_dims,pos=pos,comp_flag=4,mean=c_mean,stdv=c_stdv,cov=c_cov
means[
,j]=c_mean
stdv[,j]=c_stdv
cov[
,*,j]=c_cov
endfor
envi_doit,‘class_doit’,fid=fid,dims=dims,pos=pos,$
r_fid=r_fid,out_name=out_file,method=2,$
mean=means,stdv=stdv,cov=cov,num_classes=num_classes,lookup=lookup,$
class_names=class_names

END

你可能感兴趣的:(IDL)