pro gifbar,img,imgmin,imgmax,ct=ct,tc=tc,wc=wc,fname=fname,dispwin=dispwin, $ wintitle=wintitle,imgmean=imgmean,noframe=noframe,fc=fc,$ barends=barends,title=title ;+ ; NAME: ; gifbar ; PURPOSE: ; Display an image in color with an annotated color bar beside it ; for reference. Image can also be written out as a GIF image. Images ; will be scaled to as close to 256x256 as possible. ; CALLING SEQUENCE: ; gifbar, img[, imgmin, imgmax, ct=ct, tc=tc, fname=fname, ; dispwin=dispwin, wintitle=wintitle, /imgmean, /noframe, ; fc=frame_color, barends=[barmin,barmax],title=title] ; INPUTS: ; img = an IDL image array ; imgmin = minimum value to be represented by lowest color ; imgmax = maximum value to be represented by brightest color ; if these values are not both given then they will be ; computed. This may lead to some strange boundaries and ; color divisions. ; ct = IDL color table number (default is 27 - EOS b) ; tc = text color value from 0-255 (default is 0) ; wc = wash color (to pre-erase the window with a color) ; fname = filename for output GIF image; the .gif extension will be added ; dispwin = window number for tv display ; wintitle = window title ; imgmean = switch to use the image mean rather than median ; noframe = switch to turn off drawing a frame around the image. A frame ; is drawn to distinguish between the zero level of an image and ; the zero level of the screen background. ; fc = color for the frame around the image (default is 255) ; barends = a two-element vector for the lower and upper bounds ; for the color bar --- zoom in on a piece of it ; title = a title in the image ; OUTPUTS: ; The scaled image is displayed with the color bar beside it and then ; optionally written out to a GIF image. ; MODIFICATION HISTORY: ; Written 18 SEP 96 by David R. Klassen ; Added section to create ps output and to automatically ; add extensions to file names. 20 APR 2000 by David R. Klassen ; Added frame drawing and switch to turn it off. 5 June 2001 by DRK. ;- on_error,1 if n_params() lt 1 then begin print,' Syntax: gifbar,img[, imgmin, imgmax, ct=color_table,' print,' tc=text_color, fname=file_name, dispwin=window_number,' print,' wintitle=window_title, /imgmean, /noframe,' print,' fc=frame_color, barends=[barmin,barmax], title=title]' return endif ; imgmed=median(img) imgmoment=moment(img) if keyword_set(imgmean) then imgmed=imgmoment(0) sigma=sqrt(imgmoment(1)) if n_params() eq 1 then begin imgmin=imgmed-2*sigma imgmax=imgmed+2*sigma endif imgmin=imgmin(0) imgmax=imgmax(0) if n_elements(dispwin) eq 0 then dispwin=0 print,'Median image value:',imgmed print,'Image display minimum and maximum',imgmin,imgmax if n_elements(ct) eq 0 then ct=27 if n_elements(tc) eq 0 then tc=255 ;if n_elements(fc) eq 0 then fc=255 if n_elements(wc) eq 0 then wc=0 if n_elements(title) ne 0 then tspace=25 else tspace=0 if n_elements(title) ne 0 then ftspace=26 else ftspace=0 ; Kludge to hard code some nice colors for colorsets 42 and 43 ; since I envision using them a lot and don't want to remember ; to set the text and wash colors if ct eq 42 and wc eq 0 then wc=112 if ct eq 43 and wc eq 0 then wc=128 if ct eq 44 and wc eq 0 then wc=128 if ct eq 45 and wc eq 0 then wc=128 if ct eq 46 and wc eq 0 then wc=126 ;if ct eq 42 and tc eq 255 then tc=0 ;if ct eq 43 and tc eq 255 then tc=0 ; End of Kludge if n_elements(fc) eq 0 then fc=tc test=size(img) winwidth=test[1]+144>400 winheight=test[2]+44+tspace>300+tspace zoom=round(256./test[1]<256./test[2]) print,winwidth,winheight,zoom if zoom eq 0 then zoom=1.0 newimg=bytscl(rebin(img,test[1]*zoom,test[2]*zoom),min=imgmin,max=imgmax) frame=make_array(test[1]*zoom+2,test[2]*zoom+2,/byte,value=fc) bar=bytarr(20,256) wash=bytarr(winwidth,winheight) if n_elements(barends) ne 2 then barends=[0,255] ;if n_elements(barends) eq 2 then begin nbars=fix(barends[1]-barends[0]+1) ; print,nbars,256/nbars for j=0,nbars-1 do for i=j*(256/nbars),(j+1)*(256/nbars)-1 do bar[*,i]=j ;endif else for i=0,255 do bar[*,i]=i if n_elements(wintitle) eq 0 then wintitle='GIFBAR' else wintitle=wintitle(0) window,dispwin,xs=winwidth,ys=winheight,title=wintitle ;if ct eq 41-44 use special color programs else loadct,ct case ct of 41: lct_tnt 42: lct_gwm,3 43: lct_gwm,2 44: lct_gwm,1 45: lct_gwm 46: ctload,20,/brewer,/reverse else: loadct,ct endcase wash[*]=wc tv,wash ;erase tv,frame,8,((winheight-ftspace-test[2]*zoom)-1)/2 tv,newimg,9,(winheight-tspace-test[2]*zoom)/2 tv,bar,test[1]*zoom+29,(winheight-tspace-256)/2 for i=0,287,32 do begin b=i & y=b+(winheight-tspace-256)/2 step=(imgmax-imgmin)/256. & value=b*step*nbars/256+imgmin xyouts,test[1]*zoom+54,y,'!B'+strno(value,/dp4),/device,align=0,color=tc,$ charsize=1.25,charthick=2 endfor if n_elements(title) ne 0 then $ xyouts,winwidth/2.0,winheight-1.25*tspace,title,charsize=2.00,$ charthick=2,align=0.5,/device,color=tc if n_elements(fname) ne 0 then begin ; Making the PNG file by displaying to z-buffer origdevice=!d.name set_plot,'z' device, set_resolution=[winwidth,winheight] case ct of 41: lct_tnt 42: lct_gwm,3 43: lct_gwm,2 44: lct_gwm,1 45: lct_gwm 46: ctload,20,/brewer,/reverse else: loadct,ct endcase ; erase wash[*]=wc print,wc tv,wash tv,frame,8,((winheight-ftspace-test[2]*zoom)-1)/2 tv,newimg,9,(winheight-tspace-test[2]*zoom)/2 tv,bar,test[1]*zoom+29,(winheight-tspace-256)/2 for i=0,287,32 do begin y=i+(winheight-tspace-256)/2 step=(imgmax-imgmin)/256. & value=i*step+imgmin xyouts,test[1]*zoom+54,y,'!B'+strno(value,/dp4),/device,align=0,$ color=tc,charsize=1.03125,charthick=2 endfor if n_elements(title) ne 0 then $ xyouts,winwidth/2.0,winheight-1.25*tspace,title,charsize=1.5,$ charthick=2,align=0.5,/device,color=tc tvlct,r,g,b,/get write_png,fname+'_'+strno(ct,/two)+'.png',tvrd(),r,g,b ; Making the EPS version set_plot,'ps',/copy,/interp device,filename=fname+'_'+strno(ct,/two)+'.eps' device,/color ; device,bits_per_pixel=24 device,bits_per_pixel=8 device,/encapsul div=29. mul=35. device,xsize=winwidth/div,ysize=winheight/div wash=bytarr(winwidth,winheight) wash[*]=wc tv,wash tv,frame,8/div,(((winheight-ftspace-test[2]-1)*zoom)/2)/div,$ xsize=(test[1]+2)*zoom/div,ysize=(test[2]+2)*zoom/div,/centimeter tv,newimg,9/div,((winheight-tspace-test[2]*zoom)/2)/div,$ xsize=test[1]*zoom/div,ysize=test[2]*zoom/div,/centimeter tv,bar,(test[1]*zoom+29)/div,((winheight-tspace-256)/2)/div,$ xsize=20/div,ysize=256/div,/centimeter for i=0,287,32 do begin y=(i+(winheight-tspace-256)/2)*mul step=(imgmax-imgmin)/256. & value=i*step+imgmin xyouts,(test[1]*zoom+50)*mul,y,'!B'+strno(value,/dp4),/device,$ align=0,color=tc,charsize=1.25,charthick=4 endfor if n_elements(title) ne 0 then $ xyouts,(winwidth/2.0)*mul,(winheight-1.25*tspace)*mul,title,$ charsize=1.85,charthick=4,align=0.5,/device,color=tc device,/close_file set_plot,origdevice endif end