Raster Palette Manipulations Example

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

A palette represents each pixel in a raster and lists the RGB colors associated with each pixel. FME has several transformers that can be used to manipulate whole palettes, such as RasterPaletteInterpretationCoercer and RasterPaletteGenerator. However, sometimes there can be a need to access and edit each pixel. FME has two transformers that enable extracting palettes and adding them to/from an attribute: RasterPaletteExtractor and RasterPaletteAdder.

Scenario

Let's take a simple raster with several distinct colors:

initialraster.png

1. Open the extractPalette.fmwt workspace

Run the extractPalette.fmwt template workspace, which will take the initial raster (pictured above) and extract the palette using the RasterPaletteExtractor transformer.

extractpalette.png

2. View _palette

In the FME Data Inspector, which should open after the workspace runs, highlight the entire raster to view its attributes. In the Feature Information Window, double-click the _palette attribute value; this will open the palette information.

featureinformation.png

3. Understanding the Palette

stringindi.png

The first line is the interpretation of the raster palette; in this case, it's RGBA32. All other lines start with a key value, followed by the color expressed according to the interpretation: the first three numbers define red, green, and blue, and the fourth controls alpha and sets transparency.

Now imagine we would like to replace the pure blue color 0,0,255 (in the second row from the bottom, third column) with pure yellow, 255,255,0. In our palette, it is the key number 4.

initialraster-identified.png

To determine which key is associated with which square, in the FME Data Inspector, click on the square of interest and then, in the Feature Information Window, the key will be identified by Band 0

determinebandnumber.png

Step-by-step Instructions

Now that the key has been identified in the palette, there are two ways we can manipulate it. First, the attribute can be written to a text file, changed manually in the text file, and then a new version of the palette can be applied to the raster (Part 1). 

Alternatively, all of this can be done in a single workspace (Part 2). Depending on the use case, either method can be used.

Part 1: Editing Palette in a Text Editor

This scenario requires two workspaces. The first workspace extracts the palette. Then the palette is edited manually in a text editor and then saved. Then the second workspace is used to read in the new palette and update the raster.

1. Open the unloadPalette.fmwt Workspace (Workspace 1)

In FME Workbench open up the unloadPalette.fmwt workspace. In this workspace, a raster is read in (the one pictured above). A RasterPaletteExtractor transformer is then used to extract the palette and store it as an attribute. Using the AttributeFileWriter transformer, that attribute (_palette) is written out to disk.workspace1.png

2. Run the Workspace

When running the workspace, a dialog will appear asking for a save location for the palette attribute. Ensure this location is easy to find, as the file will be opened in the next step.

3. Open palette.txt

Find the save location set in step 2, then open palette.txt in a text editor. An advanced text editor is recommended, but any text editor will do.

4. Change the Palette

In an advanced text editor, locate line 6. Then change the line from 4 0,0,255,255 to 4 255,255,0,255. This will change the color from blue to yellow. Save the file.

changeattributevalue.png

5. Open the loadPalette.fmwt Workspace (Workspace 2)

The last step is to apply our modified palette to the source raster. Open the loadPalette.fmwt template workspace and then run the workspace. When the workspace is run, another dialog will appear; select the save location for palette.txt.

workspace2.png

This workspace reads in the original raster and the new palette using the AttributeFileReader transformer. Then, using the RasterPaletteRemover transformer, the old palette is removed, and the new one is added using the RasterPaletteAdder transformer.

6. View the New Raster

After running the workspace, FME Data Inspector will open, and the new raster can be viewed.

newraster.png

Part 2: Changing a Palette with Workbench

The previous solution does not look very nice. Changes must be made to two workspaces, or to a single workspace between steps. There is a way to do this using only one workspace.

1. Open the manipulatePalette.fmwt Workspace

Open the manipulatePalette.fmwt template workspace. This workspace reads in the initial raster, extracts the palette, and stores it as an attribute. Then, using the AttributeSplitter transformer, the palette line is split into a list element. An AttributeCreator transformer is used to assign _list{5}, which is key 4, the yellow RGB value 4 255,255,0,255. Then a ListConcatenator transformer is used to rebuild the palette. 

Finally, as in Part 1, the old palette is removed using the RasterPaletteRemover, and the new palette is added using the RasterPaletteAdder.

workspace3.png

2. Run the workspace

Run the workspace and view the new raster in the FME Data Inspector. The output should be the same as Part 1.

Conclusion

Which way is better depends on your needs in palette editing. Complex, conditional changes to large palettes can be quite tricky in Workbench; using a text editor as a visual aid might be a better option than a long chain of transformers. On the other hand, for regular production tasks, it may be worth consolidating all the modifications into a single process.

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.