>  Docs Center  >  Libraries  >  Coyote  >  CGIMAGE


  The purpose of this program is to create a TV command that works the way
  the TV command would be expected to work if it was written today, rather
  than 25 years ago. In other words, it knows the difference between an
  8-bit device and a 24-bit device, it honors the POSITION keyword like
  other graphics commands in IDL, it honors the !P.MULTI value, like other
  graphics commands in IDL, it works seamlessly with both 8-bit and 24-bit
  images. In addition to other modern features, this program can also
  display images that contain an alpha channel and can display transparent
  There is a common block in cgImage that is defined as follows upon exiting
  this command::
      _cgimage_xsize, $ ; The X size of the image.
      _cgimage_ysize, $ ; The Y size of the imge.
      _cgimage_winxsize, $ ; The X size of the window displaying the image.
      _cgimage_winysize, $ ; The Y size of the window displaying the image.
      _cgimage_position, $ ; The final position of the image in the window.
      _cgimage_winID, $ ; The window index number of the window displaying the image.
      _cgimage_current ; Set to 1 if a call to cgImage is made.
  To learn more about transparent images and cgImage see the article
  `Working with Transparent Images and cgImage <http://www.idlcoyote.com/cg_tips/transimage.php>`.




    To display an image with a contour plot on top of it, type::
        filename = FILEPATH(SUBDIR=['examples','data'], 'worldelv.dat')
        image = BYTARR(360,360)
        OPENR, lun, filename, /GET_LUN
        READU, lun, image
        FREE_LUN, lun
        thisPostion = [0.1, 0.1, 0.9, 0.9]
        cgIMAGE, image, POSITION=thisPosition, /KEEP_ASPECT_RATIO
        CONTOUR, image, POSITION=thisPosition, /NOERASE, XSTYLE=1, $
            YSTYLE=1, XRANGE=[0,360], YRANGE=[0,360], NLEVELS=10
    To display four images in a window without spacing between them::
        cgImage, image, Margin=0
        cgImage, image, Margin=0
        cgImage, image, Margin=0
        cgImage, image, Margin=0
        !P.Multi = 0
    To display four image in a window with associated color bars::
        p = [0.02, 0.3, 0.98, 0.98]
        LoadCT, 0
        cgImage, image, Position=p
        cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
        p = [0.02, 0.3, 0.98, 0.98]
        LoadCT, 2
        cgImage, image, Position=p
        cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
        p = [0.02, 0.3, 0.98, 0.98]
        LoadCT, 3
        cgImage, image, Position=p
        cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
        p = [0.02, 0.3, 0.98, 0.98]
        LoadCT, 5
        cgImage, image, Position=p
        cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
        !P.Multi =0
    To set a missing value to -32767 and the color white and do
        cgLoadCT, 4, /Brewer, NColors=254
        TVLCT, palette, /Get
        cgImage, image, Missing_Value=-32767, Missing_Color='white', Stretch='Clip', Clip=3
        cgImage, cgDemoData(7), CTIndex=0
        cgImage, cgDemoData(5), CTIndex=33, Transparent=50, $
            AlphaFGPosition=[0.25, 0.25, 0.75, 0.75], Missing_Value=0


        David W. Fanning
        1645 Sheely Drive
        Fort Collins, CO 80526 USA
        Phone: 970-221-0438
        E-mail: david@idlcoyote.com
        Coyote's Guide to IDL Programming: http://www.idlcoyote.com/


Modification History

      Written by: David W. Fanning, from modifications to TVIMAGE. 3 Feb 2011.
      8 Feb 2011. Added OPOSITION keyword. DWF.
      27 Feb 2011. Added keywords to make cgImage more compatible with TVImage calls. DWF.
      Color table vectors must be obtained AFTER loading the color palette. 6 March 2011. DWF.
      I have been convinced (conversations with Wayne Landsman) that if the
        CENTER keyword is set, the MINUS_ONE keyword is not needed, since
        it was created to solve the same problem. So, I have changed the
        default setting of MINUS_ONE to 0. 14 March 2011. DWF.
      Corrected a problem with restoring color tables if a PALETTE is used. 31 March 2011. DWF.
      Whoops! Documented a CHARSIZE keyword, but forgot to define it. 7 July 2011.
      Damnation! I did the same thing with the FONT keyword! 25 July 2011.
      And now a TITLE keyword! What the devil is going on!? 29 Aug 2011.
      Very slight modifications to image size and start position so that the image is
          positioned completely inside the axes. 30 Sept 2011. DWF.
      Fitting the image inside the axes causes image matching problems (and lines!) in
          other programs, so I've decided to only do positioning inside axes when the
          user asks for this capability by setting the new FIT_INSIDE keyword. 16 Nov 2011. DWF.
      Problem with transparent images with alpha channels caused by changes in the TVImage->cgImage
          transition. Added AlphaFGPosition keyword to address issues. Cleaned up the
          code and improved the internal documentation. 22 Nov 2011. DWF.
      Added the ability to stretch 2D image arrays in various ways before display. 1 Dec 2011.
      Added the ability to handle missing data in 2D arrays before display. 1 Dec 2011.
      Added a DISPLAY keyword to display the image in windows with the image aspect ratio. 2 Dec 2011.
      Added the ability to send the output directly to a file via the OUTPUT keyword. 9 Dec 2011, DWF.
      PostScript, PDF, and Imagemagick parameters can now be tailored with cgWindow_SetDefs. 14 Dec 2001. DWF.
      Modified to use cgDefaultColor for default color selection. 24 Dec 2011. DWF.
      Changes to allow better default colors, based on changes to cgColor and cgDefaultColor. 1 Feb 2012. DWF.
      I was passing the wrong MINVALUE and MAXVALUE values to the scaling function. 12 Feb 2012. DWF.
      I made cgImage aware of a "feature" of MAP_SET that sets !P.MULTI[0]=-1, which was screwing
          up the algorithm to cause cgImage to erase the display window. 28 Feb 2012. DWF.
      Added a Standard Deviation stretch, including the EXCLUDE and MULTIPLIER keywords to the
          SDevScl command. 6 June 2012. DWF.
      Now saving the image POSITION in FSC_$CGIMAGE common block, even if in PostScript, because other
          routines (e.g., cgMap) may depend on it (e.g., using ONIMAGE keyword). 26 July 2012. DWF.
      Added the ability to use escape characters in plot titles to specify cgSymbol symbols. 27 July 2012. DWF.
      Modified the way the XRANGE and YRANGE keywords work when the OVERPLOT keyword is also set. In this case,
          I will modify the image position to honor the XRANGE and YRANGE values with respect to the axes that the
          image is being overplot onto. 15 August 2012. DWF.
      Set the NOERASE keyword if the OVERPLOT keyword is set and NOERASE is undefined. 16 Aug 2012. DWF.
      Modified the way the HIST_EQUAL stretch works. Previously the image was displayed as all zeros
          if the input image had a minimum value less that zero. 21 Aug 2012. DWF.
      Fixed a problem with the INTERPOLATE variable that prevented interpolaton from occurring. 12 Sept 2012. DWF.
      A misspelled MULTIPLIER keyword was interfering with a Standard Deviation stretch. 16 Sept 2012. DWF
      Added the TRANSPARENT keyword to allow transparent display of images. 17 October 2012. DWF.
      Added the MAPCOORD keyword to allow the XRANGE and YRANGE of the image to be specified by the map
          coordinate object. 17 October 2012. DWF.
      Added CTINDEX, BREWER, and REVERSE keywords to make loading a color table palette easier. 17 October 2012. DWF.
      Now setting MISSING_VALUE pixels to completely transparent if a transparent image is created. 17 October 2012. DWF.
      Added the ability to apply a stretch to a 2D image prior to converting it to a transparent image. 18 October 2012.DWF.
      Added a FILENAME keyword so that files of known format (GeoTIFF, JPEG, PNG, etc.) can be read to supply an
          image for display. 18 October 2012. DWF.
      Fixed a problem that prevented transparent images from be displayed with !P.Multi. 20 Oct 2012. DWF.
      Provided a fix to allow transparent images in versions of IDL from IDL 6.4 and earlier. 18 Nov 2012. DWF.
      When reading a GeoTiff file, the map object created should be named mapCoord, not map, so that
          the image data ranges can be set automatically. 11 January 2013. DWF.
      Additional work to allow overplotting of transparent images. 12 Jan 2013. DWF.
      For some reason I thought I had to have transparency ON when overplotting. This turns out to be wrong
          and gets in the way of outputting to PostScript and working with some map projected images. I've
          removed this requirement in the code. I also fixed a problem in which the OUTPUT position changes
          if the TRANSPARENT keyword is used. 27 January 2013. DWF.
      I had some code dealing with XRANGE and YRANGE properties of the image when a map coodinate object
          was used with cgImage. This was inadvertently setting the XRANGE and YRANGE properties of the
          image, which was in turn causing the range values to be SAVED in the plotting system variables.
          This interferred with backward compatibility with the TV command, so I have removed it. 31 Jan 2013. DWF.
      Whoops! Typo in my last fix. Getting too old, I guess. 6 Feb 2013. DWF.
      Setting any of the MISSING_*** keywords while doing multiple plots resulted in the value
          of !P.Multi being ignored for the image. This is fixed for now, but just a warning. Setting
          these keywords creates transparent images, and makes things MUCH more complicated. So, I'm
          probably at the limit of what is possible now. :-) 30 April 2013. DWF.
      The LAYOUT keyword went on walkabout after the last changes. Restored to operation. 12 July 2013. DWF.
      The YTITLE keyword was missing when passed to cgWindow. Fixed now. 24 Oct 2013. DWF.
      Fixed a couple of places where I meant "missing_index" and used "missing_color". 26 Jan 2014. DWF.
      Added check for open graphics window when displaying alpha-channel image. 31 March 2014. DWF.
      Added XVECTOR and YVECTOR keywords. 1 April 2014. DWF.
      Fixed a problem in which the POSITION of the image was specified as an integer array when it
            should have been a floating point array. 8 January 2015. DWF.
      Added compression stretch and updated retired program references. 27 Mar 2015. DWF.


    Copyright (c) 2011-2015, Fanning Software Consulting, Inc.

© 2019 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us