Files
Introduction
Alpha compositing is the process of blending two images using alpha values to set transparency, creating a seamless image with a smooth transition between two images. This can be beneficial when combining rasters with different resolutions or spectral ranges. This tutorial demonstrates how to apply this technique in FME using a 2011 and 2022 orthophoto as source data.
Files
Due to the large file size of the raster imagery, the GeoTIFF files must be downloaded separately from the City of Vancouver's Open Data Portal or the links below. Optionally, you can copy and paste the HTTPS URL directly into the GeoTIFF reader.
Orthophoto2022 (GeoTIFF):
https://safe-kc.s3.us-west-2.amazonaws.com/Alpha+Compositing%3A+Blending+Two+Images/Orthophoto2022.zip
Orthophoto2011 (GeoTIFF):
https://safe-kc.s3.us-west-2.amazonaws.com/Alpha+Compositing%3A+Blending+Two+Images/Orthophoto2011.zip
The workspace template can be downloaded from the Files section in the right side column.
Step-by-Step Instructions
In this tutorial, we will build a workspace that creates an alpha band mask from the 2022 raster through a series of inward buffer rings, each assigned an increasing transparency value. We will combine this mask with the original 2022 raster, then mosaic it with the 2011 orthophoto using the Composite Using Alpha Band option to handle blending where the two images overlap.
Part 1: Create Alpha Band Mask on 2022 Raster
First, we will extract the raster properties and extents. Then we will create colored buffers to convert to an alpha band that will be used as the transparency attribute.
1. Read GeoTIFF
We will first work with the 2022 orthophoto we want to overlay on the 2011 orthophoto. In FME Workbench, open a blank workspace and click the Reader button from the Toolbar. In the Add Reader dialog, enter the following:
- Format: GeoTIFF (Geo-referenced Tagged Image File Format)
-
Dataset: /Orthophoto2022.tif
-
Click the ellipsis to browse to the downloaded file if you saved it locally, or paste the data HTTPS URL instead and remove the quotations
https://safe-kc.s3.us-west-2.amazonaws.com/Alpha+Compositing%3A+Blending+Two+Images/Orthophoto2022.zip
-
Click OK.
2. Extract Raster Properties
We want to be able to reference a few raster properties later in the workspace, so we will use a RasterPropertyExtractor to easily access these values. Add a RasterPropertyExtractor to the workspace and connect its Input port to the GeoTIFF reader feature type.
The properties we will reference later on include the top left X and Y coordinates, number of columns and rows, and cell spacing.
3. Create a Polygon of the Raster Extent
We want to create multiple buffers within the extent of the original raster, so we will use a RasterExtentsCoercer to create a polygon of the extent. This will be the base for the buffers.
Connect the RasterPropertyExtractor Output port to a RasterExtentsCoercer Input port.
4. Set Buffer Properties
We will add an AttributeCreator to create attributes that will be used to create the buffers. We will define properties including the number of buffers created, the size of buffers, and the combined width of the buffers.
Connect the RasterExtentsCoercer Extents Output port to an AttributeCreator Input port and set the following in the transformer parameters:
| Output Attribute | Value |
| BUFF_COUNT | 10 |
| BUFF_SIZE | -10 |
| FADE_WIDTH | @Value(BUFF_COUNT) * @Value(BUFF_SIZE) |
BUFF_COUNT will be used to define the number of buffers created. BUFF_SIZE is a negative value as we want to create buffers inward. FADE_WIDTH is calculated using the arithmetic calculator and referencing the previous output attributes and will be used later in the workspace for easy computation.
These attributes could also be created as User Parameters so the values can be easily adjusted at runtime.
5. Create Multiple Buffers
To create multiple buffers within the raster extent, we will use a custom transformer called MultiBufferer. This can be installed through FME Workbench directly by adding the transformer and accepting the install dialog. You can also download the transformer from FME Hub and import it into FME Workbench.
Connect the AttributeCreator Output port to the MultiBufferer Input port and set the following parameters:
-
Buffer Interval: BUFF_SIZE
- Click the drop-down arrow to select the attribute value
-
# of Buffers: BUFF_COUNT
- Click the drop-down arrow to select the attribute value
-
Create Donuts: Yes
- This setting is important as it creates multiple buffer rings rather than nesting polygons
6. Set Rasterizing Properties
We want to convert the buffer rings into a raster image to join with the original 2022 raster. The ImageRasterizer transformer uses the fme_color attribute to rasterize. Using an AttributeCreator, we will create a band value for coloring, then concatenate the values into an fme_color attribute.
The StringConcatenator transformer can also be used to define fme_color instead of the AttributeCreator
Add an AttributeCreator and connect its Input port to the MultiBufferer Output port. Open the AttributeCreator parameters and set the following:
| Output Attribute | Value |
| BAND_VALUE | @Evaluate(255 * (@Value(_buffer_to) / @Value(FADE_WIDTH))) |
| fme_color | @Value(BAND_VALUE),@Value(BAND_VALUE),@Value(BAND_VALUE) |
To calculate BAND_VALUE, we divide the _buffer_to location value from the MultiBufferer by the width of all buffers (FADE_WIDTH). Then, we multiply this calculation by 255 which is the maximum Alpha8 band value (0 to 255) and will give us a transparency value where 0 is transparent and 255 is opaque. The @Evaluate function is used to create an arithmetic expression for band value rather than text.
The fme_color attribute will provide the ImageRasterizer with the geometry color.
7. Rasterize the Mask
We will rasterize the buffered rings using an ImageRasterizer transformer so we can combine them to the 2022 image. Since ImageRasterizer uses fme_color to draw vector features, we will set the interpretation type to Gray8 (this can also be Red8, Blue8, or Green8). This will rasterize using the fme_color attribute to set the pixel values between 0 and 255.
Connect the Attribute_Creator_2 Output port to an ImageRasterizer Input port and set the parameters:
- Resolution Specification: Rows and Columns
-
Number of Columns (cells):
_num_columns- Click the drop-down arrow to select the attribute value we created with the RasterPropertyExtractor
-
Number of Rows (cells):
_num_rows- Click the drop-down arrow to select the attribute value we created with the RasterPropertyExtractor
-
Interpretation Type: Gray8
- We will convert this to Alpha8 later
8. Match Raster Extents with a RasterGeoreferencer
Before combining the 2022 raster with the Alpha mask, we want to ensure the extents match, otherwise the RasterCombiner with fail. We set the number of columns and rows in the ImageRasterizer, and now we will set the coordinates and cell spacing using a RasterGeoreferencer. We will reference the attribute values from the RasterPropertyExtractor output.
If you are using the data in this example, you can copy the extents listed below. If using different data, refer to the RasterPropertyExtractor output.
Connect the ImageRasterizer Raster output port to a RasterGeoreferencer Input port and set the parameters:
- Parameter Type: PointAndAngle
-
X Upper Left Coordinate:
491903.9603 -
Y Upper Left Coordinate:
5457700.205 -
X Cell Spacing:
0.07500000000000437 -
Y Cell Spacing:
0.07499999999997208
9. Convert to Alpha8 with RasterInterpretationCoercer
We want the raster mask as an alpha band, which we will do by interpreting the Gray8 band as an Alpha8 band using a RasterInterpretationCoercer. This will use the numeric pixel values and convert them to an alpha band which is used to set transparency. We will use the transparency value when we mosaic the 2022 and 2011 rasters.
Add a RasterInterpretationCoercer transformer and connect its Input port to the RasterGeoreferencer Output port. Then, set the following parameters:
- Destination Interpretation Type: Alpha8
Part 2: Preparing Data for Joining
In this section, we will prepare the rasters to be mosaicked together. Before sending the rasters through the RasterMosaicker, we want to ensure both have the same number of bands, coordinate system, and are being read in the correct order.
1. Remove the Alpha Band
Since we created an Alpha8 band mask in part 1, we need to remove the alpha band from the original 2022 image before joining with the mask. If we leave it, there will be two alpha bands in the output and the RasterMosaicker requires all rasters to have equal number of bands.
Add a RasterInterpretationCoercer connected to the GeoTIFF reader feature type, creating a new branch of transformers. Set the following parameters:
- Destination Interpretation Type: RGB24
- RGBA to RGB: Drop the Alpha Band
2. Combine the Alpha Mask with Original Raster
Now that the alpha band has been removed from the original 2022 image, we can combine the 2022 raster with the alpha mask using a RasterBandCombiner. This will join the Alpha8 mask with the 2022 RGB24 raster, creating an RGBA32 raster
Connect both RasterInterpretationCoercer’s Output ports to a RasterBandCombiner Input port:
3. Add a GeoTIFF Reader
We will now read the 2011 raster image (Orthophoto2011), which is the background raster we will mosaic with the 2022 raster.
Click the Reader button in the Toolbar and set the following parameters:
- Format: GeoTIFF (Geo-referenced Tagged Image File Format)
-
Dataset: /Orthophoto2011.tif
-
Click the ellipsis to browse to the downloaded file if you saved it locally, or paste the data HTTPS URL instead and remove the quotations
https://safe-kc.s3.us-west-2.amazonaws.com/Alpha+Compositing%3A+Blending+Two+Images/Orthophoto2011.zip
-
4. Add an Alpha Band
The source image for the 2011 orthophoto is RGB, with no alpha band. To mosaic images together, they must have the same number of bands. We can add an alpha band and assign its value using a RasterBandAdder. We’ll set the value to be 255 (the maximum Alpha8 value) which is interpreted as opaque transparency.
Add a RasterBandAdder to the canvas and connect its Input port to the Orthophoto2011 GeoTIFF reader feature type. Set the following in the RasterBandAdder parameter dialog:
- Interpretation Type: Alpha8
- Cell Value: 255
5. Add Two AttributeCreators
We want the RasterMosaicker to read the input rasters in a particular order, so the 2022 raster ends up above the 2011 raster. To do so, we will create an attribute that we will use to sort the rasters. We will use two AttributeCreators, one for each raster branch.
Add an AttributeCreator and connect it to the RasterBandCombiner Output port (2022 raster branch). Set the following parameters:
- Output Attribute: _order
- Value: 2
Add another AttributeCreator and connect it to the RasterBandAdder Output port (2011 raster branch), then set the following parameters:
- Output Attribute: _order
- Value: 1
6. Sort the Rasters
Using a Sorter, we will join the two rasters into the same branch, ordering them by the _order attribute we created. We will sort numerically in ascending order, so the 2011 raster will be first, then 2022 second.
Add a Sorter transformer and connect both the AttributeCreators (AttributeCreator_3 and AttributeCreator_4) Output ports to the Sorter Input port. Set the following parameters:
- Attribute: _order
- Method: Numeric
- Order: Ascending
- Sorting Exceptions: Output Last
7. Add a Reprojector
To ensure the two images are in the same coordinate system, we will reproject both using a Reprojector transformer. Connect the Sorter Sorted output port to a Reprojector Input port and set the destination coordinate system in the parameters:
- Destination Coordinate System: UTM84-10N
8. Add a RasterCheckpointer
This step is not required for the workspace, but it improves processing time which is beneficial for large raster datasets. Add a RasterCheckpointer connected to the Reprojector Reprojected output port.
Part 3: Mosaicking Rasters and Writing Output
The final couple of steps of this workspace are where we will combine the rasters and write the output to a GeoTIFF file. We will then view the output and observe the smooth transition along the raster seam.
1. Combine Rasters with RasterMosaicker
The RasterMosaicker is the transformer we will use to overlay the 2022 raster on the 2011 raster. We want the alpha value set from the 2022 branch to be used to set transparency, so we will composite the image using the alpha band. This will use the alpha value as transparency where the images overlap. Since we set the 2011 raster to have a constant alpha value of 255 (opaque), it it important that we sort the images in an order where the raster we want overlaid (2022) is on top, which we did previously in Part 2.
Add a RasterMosaicker connected to the RasterCheckpointer Output port and set the following parameters:
- Overlapping Value: Composite Using Alpha Band
2. Write Output to GeoTIFF
The final step before running the workspace is to write the output to a GeoTIFF file. Click the Writer button in the Toolbar and set the following parameters:
- Format: GeoTIFF (Geo-referenced Tagged Image File Format)
-
Dataset: /Output
- Set desired output location
Click OK. In the Feature Type dialog, set the file name:
- Raster File Name: AlphaComposite
Click OK to add the writer to the canvas, then connect the RasterMosaicker Output port to the GeoTIFF writer feature type.
3. Run and View Output
Click the green Run button in the Toolbar to run the complete workspace. Once the translation has succeeded, select the AlphaComposite GeoTIFF writer feature type and, in the mini toolbar, click the View Written Data button.
In the Select Dataset to View dialog, set the following:
- Format: GeoTIFF (Geo-referenced Tagged Image File Format)
-
Dataset: /Output/AlphaCompositing.tif
- Browse to the saved GeoTIFF
In the output, we can see the two images, with the 2022 raster seamlessly blending into the 2011 raster.
Additional Resources
Alpha Compositing: Transitioning to White Tutorial
RasterMosaicker Transformer Documentation
MultiBufferer Custom Transformer
RasterInterpretationCoercer Transformer Documentation
RasterCombiner Transformer Documentation
RasterPropertyExtractor Transformer Documentation
RasterExtentsCoercer Transformer Documentation
RasterGeoreferencer Transformer Documentation
RasterCheckpointer Transformer Documentation
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.