;+ ;NAME: ; DISPLAYSCALE ;PURPOSE: ; Scale images to 8 bits for display. Handles missing data gracefully. ; Can also set up a color table for effective display of missing data. ;CALLING SEQUENCE: ; result = displayscale(image [, missing=missing] [, ct=ct] $ ; [, itab=itab]) ;INPUTS: ; image = a scalar 2D image to be displayed. ;OUTPUT: ; The result is a byte scaled image, with good pixels mapped to ; the interval 1-255, and missing data set to 0. ;OPTIONAL INPUT KEYWORDS: ; missing: The value used to mark missing data in image. IEEE Infinity ; and NaN are treated as missing data whether or not this keyword ; is supplied. ; ct: If set, then use MODIFYCT to set up a new color table for ; displaying the data. It is a simple grayscale, but with red ; for missing data. If ct is set but not equal to 1, then the ; color table is created but not loaded. ;OPTIONAL OUTPUT KEYWORDS: ; itab: Index of the newly created color table. ;MODIFICATION HISTORY: ; 2006-Jun-02 C. Kankelborg ; 2006-Jun-12 C. Kankelborg. Fixed bug wherein the entire IDL ; color table file, colors1.tbl, would become filled with ; entries containing my color table. After the last entry ; was taken, MODIFYCT would crash. Now I always use entry ; number 41. ;- function displayscale, image, missing=missing, ct=ct, itab=itab if keyword_set(ct) then begin ;custom color table itab=41 r = bindgen(256) g = bindgen(256) b = bindgen(256) r[0]=255b if (ct eq 1) then modifyct, itab, "Gray, 0=RED=", $ r,g,b loadct,itab endif isize = size(image) Nx = isize[1] Ny = isize[2] if (n_elements(missing) ne 1) then missing = !values.f_nan good = finite(image) and (image ne missing) ;good pixel map ss = where(good) ;good pixel list result = bytarr(Nx,Ny) if (ss[0] ne -1) then result[ss] = 1b + bytscl(image[ss], top=254) return,result end