Description

The RasterExpressionEvaluator is a transformer that evaluates expressions on each cell in a raster, such as algebraic operations or conditional statements.

Simple Calculation Examples

Inverting Colors

This example demonstrates how to invert images with the following band interpretation list and expression:

RED8;GREEN8;BLUE8
255-A[0];255-A[1];255-A[2]

User-added image    

User-added image
The images show Heritage Mountain Elementary School and the surrounding area in Google Earth
  • See RGBColorInverter.fmwt in the attached zip file

Brightness Correction

If an image is too dark, we can boost brightness with the following simple expression:

A[0]*1.5;A[1]*1.5;A[2]*1.5

User-added image   

User-added image
Port Moody, Greater Vancouver

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 case of RGB24), and the information in those areas will be lost.
  • See BrightnessCorrection.fmwt in the attached zip file

Color Correction

User-added image

If one of the colors on an image seems to dominate over the others, we can change only one band (or apply different coefficients to different bands):
 
A[0];A[1]/1.2;A[2]

User-added image
 
  • See ColorCorrection.fmwt in the attached zip file

Color to Grayscale Conversion

Most internet sources suggest the following formula for color to grayscale conversion (and many sources also mention that depending on the image it may vary):

0.2989*A[0] + 0.5870*A[1] + 0.1140*A[2]

User-added image   

User-added image

The workspace also makes an image based on calculating average values,
 
0.3333*A[0] + 0.3333*A[1] + 0.3333*A[2]

but the first formula gives better contrast.
  • See RGB2Grayscale.fmwt in the attached zip file

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 (band interpretation is INT32):
 
INT32
A[0]/0.3048

If we inspect results in Visualizer, we will see the results of the conversion:
 
Meters      
User-added image   

                                                                              Feet
User-added image
   
  • See UnitConversion.fmwt in the attached zip file