Creating a Transparent Image in IDL

QUESTION: How can I create a graphics output image with a transparent background for inclusion in a software program like PowerPoint?

ANSWER: The easiest way to create a transparent image in IDL is to use the cgTransparentImage Coyote Library function in IDL.

The cgTransparentImage function gives you the opportunity to choose the degree of transparency with the Transparent keyword, while also allowing you to making missing values (indicated with the Missing_Value keyword) completely transparent. The image to be made transparent, can be passed directly to the function, or it can be read out of any IDL graphics window, as shown in the code here.

   cgDisplay, WID=0
   cgImage, cgDemoData(5), CTIndex=0, /Interp
   timage = cgTransparentImage(MISSING_VALUE='black', TRANSPARENT=50)
   cgDisplay, WID=1
   cgImage, cgDemoData(7), CTIndex=22
   cgImage, timage

You see the results in the figure below.

A transparent image
A transparent image created from an IDL graphics window.
 

The cgTransparent function also allows you to save the transparent image as a transparent PNG image for inclusion in other programs, such as Google Earth or Powerpoint.

   image = cgDemoData(5)
   void = cgTransparentImage(image, MISSING_VALUE=0, TRANSPARENT=50, $
     PNGFILE='ctscan_transparent.png', /NOGUI)

You also have the option of supplying color tables or palettes that are used to construct the transparent image.

   image = cgDemoData(5)
   void = cgTransparentImage(image, MISSING_VALUE=0, TRANSPARENT=50, $
     PNGFILE='ctscan_transparent.png', /NOGUI, CTINDEX=4, /BREWER, /REVERSE)
   cgImage, Dist(200,200), CTINDEX=0
   cgImage, Read_Image('ctscan_transparent.png')
A transparent image saved as a file.
A transparent image saved as a transparent PNG file.
 

Transparent images can now be displayed directly by cgImage. Simply set the Transparent keyword to the amount of transparency desired.

Google
 
Web Coyote's Guide to IDL Programming