Coyote Graphics Routines

Date: Fri Mar 27 12:14:20 2015

single page | use frames     summary     class     fields     routine details     file attributes


top cgTransparentImage


result = cgTransparentImage( [image] [, /BREWER] [, CTINDEX=integer] [, MISSING_VALUE=various] [, FILENAME=string] [, /NOGUI] [, PALETTE=byte] [, PNGFILE=PNGFILE] [, /REVERSE] [, TRANSPARENT=integer] [, WSET=long])

Creates a semi-transparent image for display. Optionally, a "missing" color or color index (for 2D images) can be set to a completely transparent value. The transparent image can be saved as a transparent PNG file.


image in optional type=byte

A 2D image or a 24-bit image with or without an alpha channel. If an alpha channel is present, it will be modified by the program.


BREWER in optional type=boolean default=0

This keyword is used only if the CTIndex keyword is used to select a color table number. Setting this keyword allows Brewer color tables to be used.

CTINDEX in optional type=integer

The index number of a color table. The Brewer and Reverse keywords will be checked to see how to load the color table into the Palette keyword. This keyword will take precidence over any colors that are loaded with the Palette keyword.

MISSING_VALUE in optional type=various

The "color" of a pixel that will be treated as a "missing" color or value. Any pixels in the image with this color value will be set completely transparent. If Color is a string, use cgColor to obtain a color triple. If Color is a non-strint scalar, this value is taken to be the missing color index in a 2D image. Otherwise, this is assumed to be a color triple that indicates the "missing" color or value in the output image. The alpha channel in the output image is set to 0 for the "missing" color, which makes this value completely transparent.

FILENAME in optional type=string

The name of an image file that can be read with READ_IMAGE. Used to select the input image if the image parameter is not used.

NOGUI in optional type=boolean default=0

Set this keyword if you do not wish to have the user confirm the name of the output PNG file selected with the PNGFile keyword.

PALETTE in optional type=byte

Set this keyword to a 3x256 or 256x3 byte array containing the RGB color vectors to be loaded before the transparent image is created. Such vectors can be obtained, for example, from cgLoadCT with the RGB_TABLE keyword:

IDL> cgLoadCT, 4, /BREWER, /REVERSE, RGB_TABLE=palette IDL> tImage = cgTransparentImage( cgDemoData(7), PALETTE=palette)
The default is to use whatever colors are loaded in the current hardware color table. A palette applies only to 2D input images.

PNGFILE in optional

If this keyword is set, the output image is written as a transparent PNG file in 4xMxN format. Optionally, this keyword can be set to the name of the output PNG file. The user will have the option of confirming the name of the output file, unless the NoGUI keyword is set.

REVERSE in optional type=boolean default=0

Set this keyword to reverse the color table vectors selected with the CTIndex keyword.

TRANSPARENT in optional type=integer default=50

The percentage of transparency desired in the output image. A number between 0 and 100.

WSET in optional type=long

If image parameter is not present, make the window indicated with this keyword the current graphics window for obtaining an image parameter. If not passed, and no image is present, then the current graphics window is used to create the image.


To create and display a transparent image:

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

Author information



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


Copyright (c) 2012, Fanning Software Consulting, Inc.


Change History:

Written, 23 October 2012 to replace Make_Transparent_Image, which was retired. DWF.

File attributes

Modification date: Fri Mar 27 11:07:37 2015
Lines: 292
Docformat: rst rst