;+ ; NAME: ; view ; PURPOSE: ; Display 2D bitmap array. Display if running X-windows. ; CATEGORY: ; Imaging ; CALLING SEQUENCE: PRO view, $ input_image = input_image, $ output_image = output_image, $ new_window = new_window, $ log_scale = log_scale, $ stretch_image = stretch_image,$ truecolorimage = TrueColorImage,$ rgbplane = RGBPlane, $ tl = tl, $ trtr= tr, $ br = br, $ bl = bl, $ center = center,$ cl = cl, $ tc = tc, $ cr = cr, $ bc = bc, $ levels = levels, $ covered=covered, $ _extra = _extra ; INPUTS: ; input_image - file name containing 2D array, or ; a 2D or 3D array ; /log_scale convert the image on a log scale ; (if the image contains negative values, the displayed ; image is alog10(INPUT-min(INPUT)+1)) ; /new_window passed to TWIN to open a new window for the image ; (by default the last window opened by TWIN is overwritten) ; OPTIONAL OUTPUT PARAMETERS: ; input_image (if input value was a file name) ; array read from input file ; output_image array actually displayed (different from input if ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType, img_read, twin, IsDisplay ; PROCEDURE: ; > The image is plotted using the TV procedure ; > img_read is used to read the file ; > 3D arrays are displayed using the twin/wallpaper option ; MODIFICATION HISTORY: ; JAN-1994, Paul Hick (UCSD) ;- ; Check for character input (i.e. a file name) InitVar, log_scale , /key InitVar, new_window , /key InitVar, TrueColorImage , /key InitVar, stretch_image , /key CASE IsType(input_image, /string) OF ; Type string: assume file name 0: BEGIN CASE size(input_image, /n_dim) OF 2: goto, DISPLAY_IMAGE 3: goto, DISPLAY_IMAGE ELSE: message, 'Only 2D and 3D-arrays can be displayed' ENDCASE END 1: file = input_image[0] ENDCASE IF NOT img_read(file,input_image,Red,Green,Blue,truecolorimage=TrueColorImage,rgbplane=RGBPlane) THEN $ RETURN message, /info, 'Extract image array using keyword INPUT_IMAGE' DISPLAY_IMAGE: TrueColorDisplay = !d.n_colors gt 256 IF TrueColorImage THEN BEGIN IF n_elements(RGBPlane) NE 3 THEN RGBPlane = [0,1,2] dim = size(input_image) IF dim[0] NE 3 THEN message, 'Image is not a truecolor (> 8 bit)' dim = where(dim[1:3] EQ 3) IF (where(RGBPlane NE [0,1,2]))[0] NE -1 THEN BEGIN CASE dim[0] OF ; Rearrange color into order red,green,blue 0: input_image = input_image[ RGBPlane, *, *] 1: input_image = input_image[ *, RGBPlane, *] 2: input_image = input_image[ *, *, RGBPlane] ELSE: message, 'Color interleave dimension not found' ENDCASE ENDIF IF NOT TrueColorDisplay THEN BEGIN input_image = color_quan(input_image,1+dim[0],RED,GREEN,BLUE) TrueColorImage = 0B ENDIF ENDIF output_image = input_image IF log_scale THEN output_image = alog10(output_image-(min(output_image, /nan)-1)) IF NOT IsDisplay() THEN RETURN ; Return if not running X-windows tmp = size(output_image) ; Pick up image dimensions IF TrueColorImage THEN BEGIN xsize = (tmp[where(tmp ne 3)])[0] ysize = (tmp[where(tmp ne 3)])[1] ENDIF ELSE BEGIN xsize = tmp[1] ysize = tmp[2] IF tmp[0] EQ 3 THEN BEGIN ; Image cube twin, /wallpaper, /delete zmax = max(output_image,min=zmin) FOR i=0,tmp[tmp[0]]-1 DO BEGIN twin, /wallpaper, xsize=xsize, ysize=ysize IF i EQ 0 AND n_elements(RED) NE 0 THEN tvlct, RED,GREEN,BLUE tv, bytscl(1.*output_image[*,*,i], top=!d.n_colors, /nan, min=zmin, max=zmax) ENDFOR return ENDIF ENDELSE winmodes = -1 windex = -1 ; Args to TWIN must exist twin, winmodes=winmodes, windex=windex, tl=tl,tr=tr,br=br,bl=bl,center=center,cl=cl,tc=tc,cr=cr,bc=bc wins = where(winmodes NE -1,nr) ; Windows opened by TWIN IF new_window THEN wins = -1 ELSE $ IF windex NE -1 THEN wins = windex ELSE $ IF nr EQ 0 THEN wins = -1 ELSE $ wins = wins[nr-1] IF wins EQ -1 THEN BEGIN ; Use first free window twin, winmodes=winmodes, _extra=_extra wins = where ( winmodes EQ -1 , nr ); windows not yet opened by twin IF nr EQ 0 THEN message, 'All TWIN windows in use' wins = wins[0] ENDIF ELSE $ ; Delete if dimensions changed twin, /delete, winnr=wins, xsize=xsize, ysize=ysize twin, /show, winnr=wins, xsize=xsize, ysize=ysize, _extra=_extra CASE IsType(levels, /defined) OF 0: BEGIN IF stretch_image THEN BEGIN IF TrueColorDisplay AND TrueColorImage THEN $ tvscl, output_image, top=!d.n_colors, /nan, true=(where(size(output_image) eq 3))[1] $ ; tv, bytscl(1.*output_image, top=!d.n_colors, /nan), true=(where(size(output_image) EQ 3))[1] $ ELSE $ tvscl, output_image, top=!d.n_colors, /nan ; tv, bytscl(1.*output_image, top=!d.n_colors, /nan) ENDIF ELSE BEGIN IF TrueColorDisplay AND TrueColorImage THEN $ tv, output_image, true=(where(size(output_image) EQ 3))[1] $ ; tv, byte(output_image), true=(where(size(output_image) EQ 3))[1] $ ELSE $ tv, output_image ; tv, byte(output_image) ENDELSE ; IF TrueColorDisplay THEN loadct, 0 ELSE IF n_elements(RED) NE 0 THEN tvlct, RED,GREEN,BLUE IF NOT TrueColorDisplay THEN IF IsType(RED, /defined) THEN tvlct, RED,GREEN,BLUE END 1: contour, /noerase,pos=[0,0,1,1],xst=1,yst=1,levels=levels,output_image ENDCASE RETURN & END