Introduction
This article will cover common imagery tasks that FME users usually carry out, such as modifying bands, resampling to change resolution, and using pyramiding to downsample an image into multiple layers.
This article will cover five tasks used in imagery analysis:
Source Data
The data that will be used for all of the examples in this tutorial is an orthophoto tile of Coal Harbour in downtown Vancouver, British Columbia, that had four bands and a resolution of 1600 x 1000 px resolution.
Band Management
FME Workbench includes transformers to manipulate bands from a raster feature. Some processes might consist of adding and/or removing bands - the RasterBandAdder and RasterBandRemover transformers accomplish this.
The following tutorial will use the RasterSelector and RasterBandRemover to remove an unnecessary alpha band from an orthophoto.
Step-by-step Instructions
1. Add a GeoTIFF Reader
The orthophoto can be found under the Files section of this article. In FME Workbench, add a GeoTIFF reader to the canvas and browse to the 06-07-NO.tif dataset. Leave all reader parameters as default.
Click OK to add the GeoTIFF Reader to the canvas. Use the Visual Preview to inspect the dataset, notice there are four bands.
2. Select the Band to Remove
Add a RasterSelector transformer to the canvas, and connect it to the GEOTIFF reader feature type. In the parameters, click the ellipsis next to Band and Palette List and select 3:, which is the alpha band.
In the RasterSelector, bands are handled on the left side of the colon (:), while palettes are selected on the right. The expression below will “select” the third band in the image, or in this case, the alpha band.
Selected bands and palettes will not be visually represented in the Visual Preview or Feature Information window. Once a selection is performed, transformers that support raster selection will only affect the selected bands and palettes.
3. Remove the Raster Band
Add a RasterBandRemover and connect it to the Output Port of the RasterSelector. The RasterBandRemover does not have any parameters to set. The transformer will remove the bands previously identified by the RasterSelector.
4. Write a GeoTIFF
Add a GeoTIFF Writer to the canvas and connect it to the Output Port of the RasterBandRemover.
Inspect the data to confirm the Alpha band was successfully removed.
Resampling Data in FME
Raster resizing in FME is carried out using the RasterResampler transformer.
Resizing is a critical operation when working with raster data. Whether you’re working with raster data, such as satellite imagery, or vector data, resampling helps you manage how many points are represented. In FME, the RasterResampler transformer resamples rasters based on specified output dimensions, cell size in ground units, or percentage of original by interpolating new cell values.
Typical Uses:
- Reducing raster resolution (by reducing the number of cells and increasing cell size)
- Coercing a raster to specific dimensions or cell (pixel) size for further processing or to match other data
- Creating thumbnail images of rasters
- Resizing images
How does it work?
The RasterResampler accepts raster features, alters the number of rows/columns, and resizes cell (pixel) size according to the parameter selections. One raster feature is output for each input feature.
Output raster resolution may be specified by set dimensions (columns and rows), cell size in ground units, or percentage of original resolution.
In this scenario, you want to change the spatial resolution of your raster dataset and set rules for aggregating or interpolating values across the new pixel sizes. This will allow you to change the cell size without changing the extent of the raster dataset. The objective of this exercise is to downsample the raster in order to reduce the file size and improve performance when displaying the raster.
Step-by-step Instructions
1. Add a GeoTIFF Reader
The source data that we will be using is an orthophoto tile of Coal Harbour in downtown Vancouver, British Columbia, with a resolution of 1600 x 1000 px resolution.
In FME Workbench, add a GeoTIFF reader to the canvas. Browse to the 06-07-NO.tf dataset. Click OK to add the reader.
2. Add a ResampleRaster
Add a RasterResampler transformer to the canvas and connect it to the GEOTIFF reader feature type. In the RasterResampler parameters, change the Resolution Specification to Percentage, then enter 50 into the Percentage parameter. We will leave the Interpolation Type as Nearest Neighbor. This option is the simplest and fastest method. Values are copied from the nearest cell.
For more information about Interpolation Type, see the RasterResampler documentation.
3. Inspecting the Resampled Data
Once the parameters on the RasterResampler have been set, connect an Inspector transformer. Run the entire workspace. View the output data in Visual Preview.
In Visual Preview, open the Feature Information Window. Notice how the Resolution has changed—it is now half of the original. The RasterResampler has decreased the resolution by 50% from 1600 x 1000 px to 800 x 500 px.
Evaluating Cells
Cell calculations can be carried out using multiple cells as the operands to evaluate defined expressions, such as arithmetic or conditional. Various operations can be performed, such as pairwise comparison, multiplication, addition, division, and subtraction.
Raster cell calculations in FME are carried out using the RasterExpressionEvaluator, RasterCellValueCalculator, and RasterSingularCellValueCalculator transformers.
In this tutorial, we will be using the RasterExpressionEvaluator transformer to modify an image.
In this tutorial, we’ll take a GeoTIFF image and invert its band colors by modifying its cells using an expression.
Step-by-step Instructions
1. Add a GeoTIFF Reader
The orthophoto can be found under the Files section of this article. In FME Workbench, add a GeoTIFF reader to the canvas and browse to the 06-07-NO.tif dataset. Leave all reader parameters as default.
2. Add a RasterExpressionEvaluator
Add a RasterExpressionEvaluator and connect it to the GEOTIFF reader feature type. In the parameters, set the Interpretation and Expression as follows:
Interpretation | Expression |
---|---|
Red8 | 255-A[0] |
Green8 | 255-A[1] |
Blue8 | 255-A[2] |
What this will do is reverse the cell color sequence, showing an inverse of the cells that are set.
3. Run the Workspace
Add an Inspector to the RasterExpressionEvaluator. Now run the workspace. In Visual Preview, notice how the cell colors are now reversed.
Pyramiding Data in FME
Pyramiding can be described as downsampling (reducing the amount of data) a raster into one or multiple layers. For example, think of Google Maps: Looking at North America—this would be the original raster. As you zoom in, it focuses on a specific area, say New York state - this would be an example of a pyramid layer.
FME Form has multiple tools for pyramiding rasters. Pyramiding is usually applied at the writing stage in a workspace. The majority of FME Forms’ raster writers support pyramiding natively.
Otherwise, for general pyramiding, a RasterPyramider transformer will create a set of pyramids for any raster data. With the RasterPyramider, pyramids can be defined by either the size of the smallest level or the number of levels of pyramiding. Again, there are parameters for the interpolation type and attributes to be added to the data.
In this tutorial, we will be opting for the first option as it gives a generalization of what pyramiding can look like.
Step-by-step Instructions
In this tutorial, we will read a GeoTIFF dataset and write it out as a GeoTIFF using the ‘Generate Pyramids’ option in the ‘Parameters’ tab.
1. Add a GeoTIFF Reader
The orthophoto can be found under the Files section of this article. In FME Workbench, add a GeoTIFF reader to the canvas and browse to the 06-07-NO.tif dataset. Leave all reader parameters as default.
2. Add a GeoTIFF Writer
Add a GeoTIFF writer to the canvas. Select a location to save the GeoTIFF. Next, set the Raster File Definition to Copy from Reader, then click OK.
3. Enable the 'Generate Pyramids' Option in the 'Parameters' Tab
Connect the GEOTIFF reader feature type to the GEOTIFF writer feature type. Double-click on the writer feature type to open the parameters. In the parameters, enable Generate Pyramids.
4. Setting 'Generate Pyramids' Options
After enabling Generate Pyramids, more options will appear. For this example, set the Number of Levels to Generate to 4. This parameter sets the number of pyramids that will be generated.
Next, set the Interpolation Type to Nearest Neighbor. This will use the interpolation method to reduce the image size.
Finally, set the Number of Rows/Columns per Tile to 128. This is basically the tile size used in the reduced-resolution images.
Once these are set, click OK to close out of the parameter dialog.
The number of pyramid levels to generate option does not include the original resolution image. Each pyramid level has half the number of rows and columns of the previous level (GeoTIFF Feature Types).
5. Run and Inspect the Pyramid Image
Now, run the workspace. After the workspace is finished, single-click on the GeoTIFF writer feature type to open the mini toolbar. Click on the View Written Data button to view the data in Visual Preview.
The Select Dataset To View dialog will open. Navigate to the GeoTIFF that was just created by clicking on the ellipsis next to Dataset. After selecting the dataset, click OK to open the dataset.
In the Visual Preview window, open the Feature Information window. Expand Unexposed Attributes to see an attribute list that was generated called geotiff_pyramid_leve{}l. This list references the pyramids that were generated (5 total).
Data Attribution
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.
Comments
0 comments
Please sign in to leave a comment.