;+ ;NAME: ; DISPLAYSCALE ;PURPOSE: ; Scale arrays 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] [, max=max] [, min=min]) ;INPUTS: ; image = an image or other numerical array of any dimensions. ;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. ; max: passed straight through to BYTSCL. ; min: passed straight through to BYTSCL. ;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. ; 2006-Jun-12 C. Kankelborg. More problems with MODIFYCT. Now ; I just use TVLCT. ; 2006-Jun-23 C. Kankelborg. Enable DISPLAYSCALE to work with ; arrays of any dimensions. ; 2006-Jun-24 C. Kankelborg. Fixed bug introduced yesterday. ; Added MAX and MIN keywords. ;- function displayscale, image, missing=missing, ct=ct, itab=itab, $ max=max, min=min if keyword_set(ct) then begin ;custom color table itab=0 r = bindgen(256) g = bindgen(256) b = bindgen(256) r[0]=255b if (ct eq 1) then tvlct, r,g,b 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 ;Now since good is a byte array of the right dimensions, with ;zeroes already marking all the bad data, turn good into the result! if (ss[0] ne -1) then good[ss] = $ bytscl(image[ss], top=254, max=max, min=min, /nan) + 1b return, good end