;+ ; :DESCRIPTION: ; Display Classification Image in IDL ; Three Methods:Quick Graphics/Direct Graphics/Object Graphics ; ; :AUTHOR: duhj@esrichina.com.cn ; ; :Date: 2014-7-10 ;- PRO DisplayClassificationImage ;启动ENVI批处理 COMPILE_OPT idl2 ENVI, /RESTORE_BASE_SAVE_FILES ENVI_BATCH_INIT ;选择文件,如果不存在则返回 file = ENVI_PICKFILE(TITLE='Select the classification image') IF ~FILE_TEST(file) THEN RETURN ;打开文件,判断如果不是分类结果,则返回 ENVI_OPEN_FILE, file, r_fid=fid ENVI_FILE_QUERY, fid, nb=nb, ns=ns, nl=nl,$ dims=dims, file_type=ft, lookup=lookup, $ class_names = classNames, NUM_CLASSES = n_classes IF fid[0] EQ -1 THEN RETURN ;如果不是分类图像,则返回 IF ft NE 3 THEN RETURN ;获取数据 data = ENVI_GET_DATA(fid=fid, dims=dims, pos=0) ;判断如果IDL版本是否低于8.0,如果低于8.0则只用直接图形法 IF !version.RELEASE LT 8.0 THEN GOTO, jump ;******************快速可视化************************************* ;显示图像 IF n_classes EQ 3 THEN rgb_table=TRANSPOSE(lookup,[1,0]) $ ELSE rgb_table = lookup i = image(data, /order, rgb_table=lookup, $ MARGIN=[.1,.1,.3,.1], window_title = 'Quick Graphics') iPos = (i.POSITION)[1] c = colorbar(target=i, tickname=classNames, $ font_name='Microsoft Yahei', font_size=12, $ position = [.75,iPos,.80,iPos+.065*n_classes], $ ORIENTATION=1, $ TEXTPOS=1, RGB_TABLE=RGB_TABLE) jump: ;******************直接图形法************************************* ;直接图形法需要修改颜色表 DEVICE, DECOMPOSED=0 ;将图像重采样至400列 new_ns = 400 new_nl = nl*400/ns window,0,XSIZE=new_ns+300, YSIZE=new_nl+100, $ title = 'Direct Graphics' ;背景色为白色 loadct, 0 ERASE,255 ;自定义颜色表 loadct, get_names=TableNames n_ColorTable = N_ELEMENTS(TableNames) MODIFYCT, 74, 'New ColorTable', $ lookup[0,*],lookup[1,*],lookup[2,*] loadct, 74 ;加载显示图像 TV, congrid(data,new_ns,new_nl), 50,50, /ORDER ;绘制颜色条 colorbarData = REBIN(INDGEN(1,n_classes),30,30*n_classes) TV, colorbarData, new_ns+100, 50 loadct, 0 ;绘制颜色条阴影 tmpData = REBIN(INTARR(1,n_classes)+180,2,30*n_classes) TV, tmpData, new_ns+130, 50 ;绘制类名 !p.FONT = 0 DEVICE, SET_FOnT='Microsoft Yahei*22' LabelX = INTARR(n_classes)+new_ns+140 LabelY = 58+INDGEN(n_classes)*30 XYOUTS,LabelX, LabelY, classNames, color=0, $ /device ;******************对象图形法************************************* ;窗口 new_nl = 400 new_ns = ns*new_nl/nl ;对象图形法窗口 oWin = IDLGRWINDOW(DIMENSIOnS=[new_ns+250,new_nl+100], $ RETAIN=2, TITLE='Object Graphics') ;图像和颜色条的IDLgrView oViewImage = IDLGRVIEW(DIMENSIOnS=[new_ns,new_nl], $ VIEWPLANE_RECT=[0,0,ns,nl], LOCATION=[50,50]) ;容器IDLgrModel oModel = IDLGRMODEL() ;图像对象IDLgrImage oImage = IDLGRIMAGE(ROTATE(data, 7)) ;颜色表 oPalette = IDLGRPALETTE(lookup[0,*],lookup[1,*],lookup[2,*]) oImage.SetProperty, PALETTE=oPalette ;显示图像 oViewImage.Add, oModel oModel.Add, oImage oWin.Erase ;初始化颜色条 oColorbar = IDLgrColorbar(lookup[0,*],lookup[1,*],lookup[2,*], $ MAJOR=6, SHOW_AXIS=2, TICKLEN=0, $ TICKVALUES=INDGEN(n_classes)+0.5) ;字体 oFOnt= IDLGRFONT('Microsoft Yahei', SIZE=12) ticktext = IDLGRTEXT(classNames, FOnT=oFont) oColorbar.SetProperty, ticktext = ticktext, $ DIMENSIOnS=[30,30*n_classes], $ show_outline = 1 ;颜色条容器 IDLgrView oViewColorbar = IDLGRVIEW(LOCATION=[new_ns+100,50], $ DIMENSIOnS=[200,new_nl], VIEWPLANE_RECT=[0,0,200,new_nl]) oModelColorbar = IDLGRMODEL() oViewColorbar.Add, oModelColorbar oModelColorbar.Add, oColorbar ;显示图像和颜色条 oScene = IDLGRSCENE() oScene.Add, oViewImage oScene.Add, oViewColorbar ;绘制图像和颜色条 oWin.Draw, oScene END
|