;------------------------------------------------------------- ;+ ; NAME: ; IMG_DISP ; PURPOSE: ; Display a given image. ; CATEGORY: ; CALLING SEQUENCE: ; img_disp, img ; INPUTS: ; img = Input image. in ; 2-d array, 3-d array, or file name. ; KEYWORD PARAMETERS: ; Keywords: ; MAG=mag Mag factor (def=1). ; SMAG=smag Like MAG but smooth image first. ; TITLE=ttl Image window title. Defaults to name and size. ; /CURRENT Use current window if correct size. ; /ORDER display the image reversed in Y. ; ERROR=err error flag: 0=ok, 1=not 2-D or 3-D, ; 2=wrong number of color channels for 3-D array. ; 3=file not read. ; OUTPUTS: ; COMMON BLOCKS: ; NOTES: ; Note: Normally used for byte images but may also be ; be used for INT and UINT images. These will scale ; -32768 to 32677 and 0 to 65536 to 0 to 255 for display. ; MODIFICATION HISTORY: ; R. Sterner, 2002 Jun 03 ; R. Sterner, 2002 Jun 11 --- Allowed INT and UINT images. ; ; Copyright (C) 2002, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- pro img_disp, imag, title=ttl, current=curr, $ order=order, mag=mag, smag=smag, error=err, help=hlp if (n_params(0) lt 1) or keyword_set(hlp) then begin print,' Display a given image.' print,' img_disp, img' print,' img = Input image. in' print,' 2-d array, 3-d array, or file name.' print,' Keywords:' print,' MAG=mag Mag factor (def=1).' print,' SMAG=smag Like MAG but smooth image first.' print,' TITLE=ttl Image window title. Defaults to name and size.' print,' /CURRENT Use current window if correct size.' print,' /ORDER display the image reversed in Y.' print,' ERROR=err error flag: 0=ok, 1=not 2-D or 3-D,' print,' 2=wrong number of color channels for 3-D array.' print,' 3=file not read.' print,' Note: Normally used for byte images but may also be' print,' be used for INT and UINT images. These will scale' print,' -32768 to 32677 and 0 to 65536 to 0 to 255 for display.' return endif if datatype(imag) eq 'STR' then begin ;---- Try to read image ----------- img = read_image(imag, r, g, b) ;---- Image not read? ------------- if n_elements(img) eq 1 then begin print,' Error in img_disp: Image not read: '+img err = 3 return endif ;---- Deal with IDL PNG bug -------- filebreak, imag, ext=ext if strlowcase(ext) eq 'png' then begin ; Handle IDL 5.3 png bug. if !version.release lt 5.4 then img=img_rotate(img,7) endif ;---- Deal with palette image ---------- if n_elements(r) gt 0 then begin ; 8-bit palette image. if n_elements(smag) ne 0 then begin ; Requested smoothing. rr = r(img) ; Must smooth RGB components. gg = g(img) ; so get components and bb = b(img) ; merge. img = img_merge(rr,gg,bb) endif endif endif else begin img = imag endelse ;------- Allow images of type INT and UINT -------- ;--- Translate to byte: min->0, max->255 ---------- typ = datatype(img) if (typ eq 'INT') or (typ eq 'UIN') then begin tb = byte(round(maken(0.,255.,65336))) if typ eq 'INT' then add=32768L else add=0 img = tb(img+add) endif ;-------- Mag factor ----------------- if n_elements(mag) ne 0 then begin if mag ne 1 then img = img_resize(img, mag=mag) endif ;-------- SMag factor ----------------- if n_elements(smag) ne 0 then begin if smag le 0 then return sm = round(1./smag) img = img_smooth(img,sm) if smag ne 1 then img = img_resize(img, mag=smag) endif ;-------- Display window ---------------------- img_shape, img, nx=nx, ny=ny, true=tr, err=err; Image shape. if err ne 0 then return if n_elements(ttl) eq 0 then begin ; Window title. if datatype(imag) eq 'STR' then begin filebreak, imag, nvfile=nam ttl = nam + ': ' endif else ttl='' ttl = ttl+strtrim(nx,2)+' x '+strtrim(ny,2) endif if keyword_set(curr) then begin if (!d.x_size ne nx) or (!d.y_size ne ny) then begin make_window, nx,ny, title=ttl endif endif else make_window, nx,ny, title=ttl ;-------- 2-D image -------------------------- if tr eq 0 then begin if n_elements(r) gt 0 then begin ; 8-bit palette image. device, get_decomp=decomp device,decomp=0 tvlct,r,g,b tv,img,order=order device,decomp=decomp endif else begin ; 8-bit gray scale image. tv,img,order=order endelse return endif ;-------- 3-D image -------------------------- tv, img, true=tr,order=order end