PRO ImageProbeHandler,event thisEvent=Tag_Names(event, /Structure_Name) IF thisEvent EQ 'WIDGET_BASE' THEN BEGIN Widget_Control,event.top, Get_UValue=info, /No_Copy info.drawHeight=event.y info.drawWidth=event.x Widget_Control,info.drawID, Draw_XSize=event.x,$ Draw_YSize=event.y Wset,info.wid imageColors=!D.Table_Size-4 Erase TVImage,BytScl(*info.img,Top=imagecolors-1),$ Position=info.imagePosition Widget_Control,event.top, Set_UValue=info, /No_Copy ENDIF END PRO ImageProbeDraw,event Widget_Control,event.top,Get_UValue=info,/No_Copy Wset,info.wid ; Get the dimensions of the original image sz=Size(*info.img) ncol=sz[1] & nrow=sz[2] ; Get the top of the image in the window from the Position ; This is a normalized value relative to the window height. imTop=(info.imagePosition)[3] ; Determine which row of the original image corresponds to the ; click position. r=Round((event.y/imTop)*sz[2]/info.drawHeight) ; Determine the column in the original image that corresponds to ; the click position c=Round(Float(event.x)*sz[1]/info.drawWidth) IF NOT info.probe THEN BEGIN ; The following section draws the profile associated with ; a slice across the image and handles the dropdown lines ; from the slice plot. ; ; When info.probe is true then clicks in the graphics area ; are used to probe the value of the image rather than to ; draw image profiles. ; IF event.type EQ 1 THEN BEGIN ; If the click falls within the image, then draw a line across the image ; to indicate where the slice is taken and plot the slice profile in the ; top area of the window. IF r LT sz[2] THEN BEGIN ; First, refresh the display imageColors=!D.Table_Size-4 Erase TVImage,BytScl(*info.img,Top=imagecolors-1),$ Position=info.imagePosition ; Mark the horizontal slice PlotS,[0,info.drawWidth],[event.y,event.y],/Device,Color=!D.Table_Size-3 ; Plot the slice profile in the graphics area Plot,(*info.img)[*,r],Position=info.grPosition,/NoErase,$ Color=!D.Table_Size-2,XTickv=[0,ncol/4,ncol/2,3*ncol/4,ncol],xticks=4 ; Remember the row and column of the click in the graphics window info.xPos=event.x info.yPos=event.y ENDIF ; If the click falls within the graphics part of the window then draw a vertical ; line down across the image in that column. IF event.y GT info.grPosition[1]*info.drawHeight THEN BEGIN PlotS,[event.x,event.x],[event.y,info.yPos],/Device,Color=!D.Table_Size-3 end ENDIF ENDIF ELSE BEGIN ; This section is used when image probing is turned on. ; A mouse-up within the image area causes the column, row ; and image value to be displayed in the text box. IF event.type EQ 1 AND c LT sz[1] AND r LT sz[2] THEN BEGIN s1='X:'+ String(Format='(I3)',c) s2=' Y:'+ String(Format='(I3)',r) s3=' Value:' + String(Format='(I3)',(*info.img)[c,r]) Widget_Control,info.textID,Set_Value=[s1,s2,s3] ENDIF ENDELSE Widget_Control,event.top,Set_UValue=info,/No_Copy END PRO ImageProbeHistogram,event Widget_Control,event.top,Get_UValue=info,/No_Copy h=Histogram(*info.img) imageColors=!D.Table_Size-4 Erase TVImage,BytScl(*info.img,Top=imagecolors-1),$ Position=info.imagePosition Plot,h[1:255],Position=info.grPosition,/NoErase,$ Color=!D.Table_Size-2 Widget_Control,event.top,Set_UValue=info,/No_Copy END PRO ImageProbeNew,event ; This procedure opens a new image and displays it in the ; graphics window. Widget_Control,event.top,Get_UValue=info,/No_Copy fname=Dialog_Pickfile(PATH=info.fpath,/Read) n=RSTRPOS(fname,'\') info.fpath=StrMid(fname,0,n+1) ;Remember the path n=RSTRPOS(fname,'.') type=StrUPCase(StrMid(fname,n+1)) CASE type OF 'BMP': *info.img=Read_BMP(fname) 'GIF': Read_Gif,fname,*info.img 'JPG': Read_Jpeg,fname,*info.img 'JPEG': Read_Jpeg,fname,*info.img 'PICT': Read_PICT,fname,*info.img 'PNG': *info.img=Read_PNG(fname) 'TIF': *info.img=Read_Tiff(fname) 'TIFF': *info.img=Read_Tiff(fname) ENDCASE imageColors=!D.Table_Size-4 Erase TVImage,BytScl(*info.img,Top=imagecolors-1),$ Position=info.imagePosition ; Refresh the text box Widget_Control,info.textID,Set_Value=['X: ',' Y: ',' Value: '] Widget_Control,event.top,Set_UValue=info,/No_Copy END PRO ImageProbePoke,event Widget_Control,event.top,Get_UValue=info,/No_Copy IF info.probe THEN BEGIN Widget_Control,event.ID,Set_Value='Start Probe' info.probe=NOT info.probe ENDIF ELSE BEGIN Widget_Control,event.ID,Set_Value='Stop Probe' info.probe=NOT info.probe END Widget_Control,event.top,Set_UValue=info,/No_Copy END PRO ImageProbeQuit,event Widget_Control,event.top,/Destroy END PRO ImageProbeCleanup,tlb Widget_Control,tlb,Get_UValue=info,/No_Copy IF N_Elements(info) EQ 0 THEN RETURN Ptr_Free,info.img END PRO ImageProbe,$ image, $ ; The image data Title=title ; Optional title IF N_Elements(image) EQ 0 Then image=LoadData(7) IF N_Elements(title) EQ 0 Then title="Image Probe Program" Catch, theError IF theError NE 0 THEN BEGIN Catch, /cancel ok=Error_Message(Traceback=1) RETURN ENDIF tlb = Widget_Base(Column=1,TLB_Size_Events=1,$ Title=title) btnBaseID=Widget_Base(tlb,Row=1) ;fileID=Widget_Button(menubarID,Value='File',/Menu) newID=Widget_Button(btnBaseID,Value='New Image',$ Event_Pro='ImageProbeNew') histID=Widget_Button(btnBaseID,Value='Histogram',$ Event_Pro='ImageProbeHistogram') pokeID=Widget_Button(btnBaseID,Value='Start Probe',$ Event_Pro='ImageProbePoke') quitID=Widget_Button(btnBaseID,Value='Quit',$ Event_Pro='ImageProbeQuit') textID=Widget_Text(btnBaseID,Value=['X: ',' Y: ',' Value: ']) drawID=Widget_Draw(tlb,XSize=400,YSize=400,/Button_Events,$ Event_Pro='ImageProbeDraw') Widget_Control,tlb,/realize Widget_Control,drawID,Get_Value=wid WSet,wid grPosition=[0.0,0.75,1.0,1.0] imagePosition=[0.0,0.0,1.0,0.7] imageColors=!D.Table_Size-4 TVImage,BytScl(image,Top=imagecolors-1),Position=imagePosition CD,Current=fpath ;Path to the current directory info={img:Ptr_New(image),drawID:drawID,wid:wid,grPosition:grPosition,$ drawWidth:400,drawHeight:400,probe:0,textID:textID,fpath:fpath,$ imagePosition:imagePosition,clickType:-1,xPos:0,yPos:0} Widget_Control,tlb,Set_UValue=info yellow=getColor('yellow',!D.Table_Size-3) white=getColor('white',!D.Table_Size-2) black=getColor('black',!D.Table_Size-1) XManager,'ImageProbe',tlb,/No_Block,Event_Handler='ImageProbeHandler',$ Cleanup='ImageProbeCleanup' END