Simple Examples Using the RasterExpressionEvaluator Transformer

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

The RasterExpressionEvaluator is a transformer that evaluates expressions on each cell in a raster, such as algebraic operations or conditional statements. This article will demonstrate commonly used raster transformations using the RasterExpressionEvaluator.

The basic syntax when using the RasterExpressionEvaluator is:

  • A[x] Band x of raster feature A
  • B[x] Band x of raster feature B

Bands start counting at zero (so a three-band raster is A[0], A[1], and A[2]). For more information on syntax or other examples, see the RasterExpressionEvaluator or the articles in the Additional Resources section.

Step-by-step Instructions

The following five examples have the same basic steps to create the workflow; the only differences are the input dataset and the expressions in the RasterExpressionEvaluator. The full steps are provided for Example 1; the other four examples include only instructions for the dataset and expressions.

To follow along with the tutorial, please download the data from the article's Files section.

Example 1: Inverting Colors

This example demonstrates how to invert images.

colorize.png

The images show Heritage Mountain Elementary School and the surrounding area in Google Earth

1. Create a New Workspace

Open FME Workbench and create a blank workspace.

NewWorkspace.png

2. Add a PNG (Portable Network Graphics) Reader

Add a reader to the canvas by clicking on the Reader button on the top menu bar or by going to Readers > Add Reader. In the Add Reader dialog, set the following:

Reader1.png

3. Evaluate Raster

Click on the negative reader feature type to select it. Then add a RasterExpressionEvaluator transformer to the canvas by typing “RasterExpressionEvaluator” to bring up the list of FME Transformers in the Quick Add Search. Select the RasterExpressionEvaluator from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it.

QuickAdd.png

Connection.png

Double-click on the RasterExpressionEvaluator to open the parameters. In the parameters, since we have only one input parameter, we will set Mode to One Raster; the raster will be referenced using the A variable. If we had two rasters, the other would be B. Next, set the Interpretation and Expression as follows:

  • Interpretation: Red8
    • Expression: 255-A[0]
  • Interpretation: Green8
    • Expression: 255-A[1]
  • Interpretation: Blue8
    • Expression: 255-A[2]

Click OK.

Raster1.png

If you are unsure which band interpretation corresponds to which number, open the raster in Visual Preview and inspect a single pixel. In the Feature Information window, each band will have its corresponding interpretation listed.

FeatureWindow.png

4. Run Workspace

Connect an Inspector transformer to the RasterExpressionEvaluator Result output port.

Workspace.png

Run the workspace by clicking the Run button on the top toolbar, or by selecting Run > Run Workspace from the top menu bar.

Run.png

After running the workspace, the data will be displayed in Visual Preview.

Example 2: Brightness Correction

If an image is too dark, we can boost the brightness

brightness.png

Port Moody, Greater Vancouver

1. Add a JPEG Reader

In a blank workspace, add a reader to the canvas and set the following parameters:

Click OK to add the reader to the canvas.

Reader2.png

2. Increase Brightness

Add a RasterExpressionEvaluator to the canvas and connect it to the JPEG reader. In the parameters, set the Mode to One Raster and input the following expression:

  • Interpretation: Red8
    • Expression: A[0]*1.5
  • Interpretation: Green8
    • Expression: A[1]*1.5
  • Interpretation: Blue8
    • Expression: A[2]*1.5

Click OK.

Raster2.png

This expression multiples each band by 1.5. Note that this method should be used cautiously - if there are bright areas in the image, they will reach or exceed the maximum value (255 in my example), which will make them purely white (255, 255, 255 in the case of RGB24), and the information in those areas will be lost.

Example 3: Color Correction

If one of the colors in an image seems to dominate over the others, we can change only one band (or apply different coefficients to different bands).

colorcorrect.png

Port Moody, Greater Vancouver

1. Add a JPEG Reader

In a blank workspace, add a reader to the canvas and set the following:

Click OK.

Reader3.png

2. Correct Color

Add a RasterExpressionEvaluator to the canvas and connect it to the JPEG reader. In the parameters, set the Mode to One Raster and input the following expression:

  • Interpretation: Red8
    • Expression: A[0]
  • Interpretation: Green8
    • Expression: A[1]/1.2
  • Interpretation: Blue8
    • Expression: A[2]

Click OK.

Raster3.png

Since the image appears greener, we are decreasing the green band by 1.2.

Example 4: Color to Grayscale Conversion

Most sources suggest the following formula for a color-to-grayscale conversion (and many sources also mention that, depending on the image, it may vary). There are two commonly used formulas. The first formula gives better contrast.

Formula 1:

greyscale.png

Vancouver, British Columbia

1. Add a JPEG Reader

In a blank workspace, add a reader to the canvas and set the following:

Click OK.

Reader4.png

2. Convert to Greyscale

Add a RasterExpressionEvaluator to the canvas and connect it to the JPEG reader. In the parameters, set the Mode to One Raster and input the following expression:

  • Interpretation: Grey8
    • Expression: 0.2989*A[0] + 0.5870*A[1] + 0.1140*A[2]

Click OK.

Raster4.png

Formula 2:

greyscale2.pngVancouver, British Columbia

3. Convert to Greyscale

Add another RasterExpressionEvaluator to the canvas and connect it to the JPEG reader. In the parameters, set the Mode to One Raster and input the following expression:

  • Interpretation: Grey8
    • Expression: 0.3333*A[0] + 0.3333*A[1] + 0.3333*A[2]

Click OK.

Raster4-2.pngWorkspace4.png

Example 5: Unit Conversion

Conversion between all kinds of units is a very natural operation for RasterExpressionEvaluator. In this example, we take a numeric raster representing a DEM in meters and convert the units into feet:

units.png

North Vancouver, Greater Vancouver

1. Add a CDED Reader

In a blank workspace, add a reader to the canvas and set the following:

Click OK.

Reader5.png

2. Convert Units

Add a RasterExpressionEvaluator to the canvas and connect it to the CDED reader. In the parameters, set the Mode to One Raster and input the following expression:

  • Interpretation: Int8
    • Expression: A[0]/0.3048

Click OK.

Raster5.png

Additional Resources

Advanced cell color manipulation with masks in the RasterExpressionEvaluator

Raster Calculations and Raster Palettes | NDVI Calculator ​​​​​​​

Elevation Zoning Scenario - Reclassify Rasters Using the RasterExpressionEvaluator ​​​​​​​

Using Conditions with the RasterExpressionEvaluator Transformer

Was this article helpful?

We're sorry to hear that.

Please tell us why.

As of January 14th, 2026, comments on knowledge base articles have been closed. To make sure questions don’t get missed and to enable more community support, we’ve moved discussions to the FME Community. If you have a question or a comment about this article, please create a new post or create a support ticket.