IDL编程实现图像处理.docx
- 文档编号:5516236
- 上传时间:2022-12-18
- 格式:DOCX
- 页数:9
- 大小:17.08KB
IDL编程实现图像处理.docx
《IDL编程实现图像处理.docx》由会员分享,可在线阅读,更多相关《IDL编程实现图像处理.docx(9页珍藏版)》请在冰豆网上搜索。
IDL编程实现图像处理
IDL编程实现图像处理
proexample
ENVI,/RESTORE_BASE_SAVE_FILES
ENVI_BATCH_INIT
tlb=widget_base(column=1,mbar=mbar,title='Example',tlb_frame_attr=1,xoffset=500,yoffset=100,xsize=800,ysize=600,RESOURCE_NAME='example')
filemenu=widget_button(mbar,value='File')
fileopt1=widget_button(filemenu,value='Open',event_pro='open_event')
fileopt2=widget_button(filemenu,value='Save',/menu)
Save1=widget_button(fileopt2,value='binary',uname='savebinary')
Save2=widget_button(fileopt2,value='jpg',uname='savejpg')
Save3=widget_button(fileopt2,value='bmp',uname='savebmp')
Save4=widget_button(fileopt2,value='tif',uname='savetif')
Save5=widget_button(fileopt2,value='dat',uname='savedat')
fileopt3=widget_button(filemenu,value='Exit',event_pro='exit_event',/separator)
editmenu=widget_button(mbar,value='Edit')
processopt1=widget_button(editmenu,value='K-LTransform',event_pro='K_L_event',/separator)
processopt2=widget_button(editmenu,value='HistogramEqualization',event_pro='HistogramEqualization_event',/separator)
processopt3=widget_button(editmenu,value='NDVI',event_pro='NDVI_event',/separator)
processopt5=widget_button(editmenu,value='ImageSmoothing',event_pro='IS_event')
processopt4=widget_button(editmenu,value='edgeenhancement',/menu)
imageopt1=widget_button(processopt4,value='robort',event_pro='robort_event')
imageopt2=widget_button(processopt4,value='sobel',event_pro='sobel_event')
imageopt3=widget_button(processopt4,value='prewitt',event_pro='prewitt_event')
helpmenu=widget_button(mbar,value='Help')
idlhelp=widget_button(helpmenu,value='IDLhelp',event_pro='help_event')
iconbase=widget_base(tlb,row=1,/frame)
subdir='resource/bitmaps'
mapfile=filepath('open.bmp',subdir=subdir)
iconopt1=widget_button(iconbase,value=mapfile,/bitmap,event_pro='open_event')
mapfile=filepath('save.bmp',subdir=subdir)
iconopt2=widget_button(iconbase,value=mapfile,/bitmap,event_pro='Save_event')
button5=widget_button(iconbase,value='new.bmp',/bitmap,event_pro='new_event')
button3=widget_button(iconbase,value='zoom_in.bmp',/bitmap,uvalue='suoxiao')
button4=widget_button(iconbase,value='zoom_out.bmp',/bitmap,uvalue='fangda')
help=widget_button(iconbase,value=filepath('help.bmp',subdirectory=['resource','bitmaps']),/bitmap,event_pro='help_event')
draw=widget_draw(tlb,x_scroll_size=780,y_scroll_size=550,xsize=1000,ysize=1000,xoffset=200,/button_events)
file=''
data=BYTARR(2,2,2)
pdata=bytarr(2,2,2)
status=0
pstate=ptr_new({draw:
draw,file:
file,data:
ptr_new(data),pdata:
ptr_new(pdata)})
widget_control,tlb,set_uvalue=pstate
widget_control,tlb,/realize
XMANAGER,'example',tlb,/no_block
end
proopen_event,event
compile_optIDL2
envi,/restore_base_save_files
envi_batch_init
widget_control,event.top,get_uvalue=pstate
filters=['*.jpg','*.bmp','*.img','*.tif','*.jpeg','*.png']
file=DIALOG_PICKFILE(/READ,FILTER=filters)
envi_open_file,file,r_fid=fid
iffideq-1thenreturn
envi_file_query,fid,dims=dims,nb=nb,nl=nl,ns=ns,bnames=bnames
pos=indgen(nb)
(*pstate).file=file
basename=file_basename(file)
f1=strpos(basename,'.')
type=strmid(basename,f1+1,strlen(basename)-f1)
type=strupcase(type)
widget_control,(*pstate).draw,get_value=draw
wset,draw
CASETYPEOF
'JPEG':
BEGIN
READ_JPEG,FILE,DATA
TV,DATA,/TRUE
*((*PSTATE).DATA)=DATA
END
'PNG':
BEGIN
READ_PNG,FILE,DATA
TV,DATA,/TRUE
*((*PSTATE).DATA)=DATA
END
'JPG':
BEGIN
READ_JPEG,FILE,DATA
TV,DATA,/TRUE
*((*PSTATE).DATA)=DATA
END
'BMP':
BEGIN
DATA=READ_BMP(FILE)
TV,DATA,/TRUE
*((*PSTATE).DATA)=DATA
END
'DAT':
BEGIN
DATA=BYTARR(NS,NL,NB)
OPENR,LUN,FILE,/GET_LUN
READU,LUN,DATA
TVSCL,DATA
FREE_LUN,LUN
*((*PSTATE).DATA)=DATA
END
'IMG':
BEGIN
data=bytarr(ns,nl,nb)
data=ENVI_GET_DATA(fid=fid,dims=dims,pos=pos)
WIDGET_CONTROL,(*pstate).draw,GET_VALUE=draw
WSET,draw
tvscl,data,/order
*((*pstate).data)=data
END
'TIF':
BEGIN
DATA=BYTARR(NS,NL,NB)
DATA=ENVI_GET_DATA(FID=FID,DIMS=DIMS,POS=POS)
TVSCL,DATA,/ORDER
*((*PSTATE).DATA)=DATA
END
'TIFF':
BEGIN
DATA=BYTARR(NS,NL,NB)
DATA=ENVI_GET_DATA(FID=FID,DIMS=DIMS,POS=POS)
TVSCL,DATA,/ORDER
*((*PSTATE).DATA)=DATA
END
ENDCASE
end
prosave_event,event
widget_control,event.top,get_uvalue=pstate
file=(*pstate).file
savefile=dialog_pickfile(title='save',path='D:
')
ifsavefileeq''thenbegin
void=dialog_message('Nofile!
',/error)
return
endif
a=strpos(savefile,'.')
b=strlen(savefile)
type=strmid(savefile,a+1,b-a)
casetypeof
'save':
begin
file=(*pstate).fname
ENVI_OPEN_FILE,file,r_fid=fid
iffideq-1thenbegin
void=DIALOG_MESSAGE('fileinputederror',/information)
ENVI_BATCH_EXIT
return
endif
filename=DIALOG_PICKFILE(title='choosefilesavedposition',filter='*.jpg')
write_jpeg,filename+'.jpg',*((*pstate).data),/true
end
'jpg':
begin
write_JPEG,savefile,data
end
'png':
begin
write_png,savefile,data
end
'bmp':
begin
write_bmp,savefile,data
end
'tif':
begin
write_tiff,savefile,data
end
'dat':
begin
openw,lun,binary,/get_lun
writeu,savefile,data
end
endcase
help,event,/struct
IFevent.SELECTTHENWIDGET_CONTROL,event.TOP,/DESTROY
end
prohelp_event,evevt
compile_optIDL2
envi,/restore_base_save_files
envi_batch_init
ONLINE_HELP
END
proexit_event,event
help,event,/struct
IFevent.SELECTTHENWIDGET_CONTROL,event.TOP,/DESTROY
end
proK_L_event,event
compile_optIDL2
envi,/restore_base_save_files
envi_batch_init
widget_control,event.top,get_uvalue=pstate
file=(*pstate).file
envi_open_file,file,r_fid=fid
iffideq-1thenbegin
return
endif
envi_file_query,fid,dims=dims,nb=nb
pos=lindgen(nb)
envi_doit,'envi_stats_doit',fid=fid,pos=pos,dims=dims,mean=avg,eval=eval,evec=evec,comp_flag=5
envi_doit,'pc_rotate',$
fid=fid,pos=pos,dims=dims,mean=avg,eval=eval,evec=evec,$
out_dt=4,out_name=out_name,out_nb=nb,r_fid=r_fid,/forward,/in_memory
envi_file_query,r_fid,dims=dims,nb=nb,ns=ns,nl=nl
data=bytarr(ns,nl,nb)
data=envi_get_data(fid=fid,dims=dims,pos=pos)
window,1,xsize=ns,ysize=nl,title='spatialprincipalcomponentanalysis'
tv,data,/order
end
prondvi_event,event
compile_optIDL2
envi,/restore_base_save_files
envi_batch_init
widget_control,event.top,get_uvalue=pstate
file=(*pstate).file
data=*((*pstate).data)
envi_open_file,file,r_fid=fid
envi_file_query,fid,dims=dims,nb=nb,ns=ns,nl=nl
pos=[4,3]-1
envi_doit,'ndvi_doit',fid=fid,pos=pos,dims=dims,/check,o_min=0,o_max=255,r_fid=r_fid,/inme_mory
envi_file_query,r_fid,dims=dims,nb=nb,ns=ns,nl=nl
data=BYTARR(ns,nl,nb)
data=ENVI_GET_DATA(fid=r_fid,dims=dims,pos=pos)
window,3,title='NDVI'
TVSCL,data,/order
end
proHistogramEqualization_event,event
widget_control,event.top,get_uvalue=pstate
data=*((*pstate).data)
file=(*pstate).file
envi_open_file,file,r_fid=fid
envi_file_query,fid,dims=dims,nb=nb,ns=ns,nl=nl
WINDOW,1,TITLE='Theoriginalimagehistogram'
plot,HISTOGRAM(data)
result=HIST_EQUAL(data);ADAPT_
WINDOW,2,xsize=ns,ysize=nl,TITLE='histogrammatching'
TV,result,/order
WINDOW,3,TITLE='Aftertheimagehistogrammatching'
plot,HISTOGRAM(result)
end
proIS_event,event
widget_control,event.top,get_uvalue=pstate
file=(*pstate).file
envi_open_file,file,r_fid=fid
envi_file_query,fid,dims=dims,nb=nb,ns=ns,nl=nl
iffideq-1thenreturn
data=smooth(*((*pstate).data),3)
window,1,xsize=ns,ysize=nl,title='smoothing'
tvscl,data,/order
end
prorobort_event,event
widget_control,event.top,get_uvalue=pstate
data=*((*pstate).data)
file=(*pstate).file
envi_open_file,file,r_fid=fid
envi_file_query,fid,dims=dims,nb=nb,ns=ns,nl=nl
DATA=DATA(*,*,1)
DATA=ROBERTS(DATA)
window,1,xsize=ns,ysize=nl,title='roberts'
tvscl,data,/order
end
prosobel_event,event
widget_control,event.top,get_uvalue=pstate
DATA=*((*PSTATE).DATA)
file=(*pstate).file
envi_open_file,file,r_fid=fid
envi_file_query,fid,dims=dims,nb=nb,ns=ns,nl=nl
DATA=DATA(*,*,1)
DATA=SOBEL(DATA)
window,1,xsize=ns,ysize=nl,title='sobel'
TVSCL,data,/ORDER
end
proprewitt_event,event
file=(*pstate).file
ENVI_OPEN_FILE,file,r_fid=fid
ENVI_FILE_QUERY,fid,dims=dims,nb=nb,ns=ns,nl=nl
IFfidEQ-1THENBEGIN
void=DIALOG_MESSAGE('window',/information)
ENVI_BATCH_EXIT
RETURN
endif
result=prewitt(*((*pstate).data))
window,1,xsize=ns,ysize=nl,title='window'
TVSCL,result,/order
*((*pstate).pdata)=result
WIDGET_CONTROL,ev.top,get_Uvalue=pstate
end
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- IDL 编程 实现 图像 处理
![提示](https://static.bdocx.com/images/bang_tan.gif)