English

How To: Set the null values of an image to transparent using Avenue

Summary

The script in this article changes the no-data cells of a single-band image to transparent. If your image is multiband, double-click the image in the table of contents and select the single-band radio button.

Procedure

  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy the following code into the new window.

    Code:
    '-- This script expects the view as the active doc and
    '-- your image theme as the first theme in the TOC

    theView = av.getactivedoc

    '-- Get the image theme from the View
    theItheme = theView.Getthemes.get(0)

    '-- Get the colormap for that image's legend
    thelegend = theItheme.getlegend
    theColormap = theLegend.Getcolormap

    '-- Make the color for the no data value transparent
    thenewColor = Color.Make
    theNewColor.SetTransparent(true)
    theColormap.SetNull(theNewColor)

    '-- Reflect the changes in the Legend
    theItheme.UpdateLegend
    theItheme.Invalidatelegend

  3. Click the Compile button.
    [O-Image] Script compile button
  4. Tile the windows so that you can see both the view and the script.
  5. Click the view, then click the script.
  6. Click the Run button.
    [O-Image] Run compiled script button
    Note:
    To reverse the effects of this script, double-click the image and click default in the legend window.