Setting NoData and Adding Alpha Bands to Remove Black Borders

Ali Mokheamer
Ali Mokheamer
  • Updated

FME Version

  • FME 2023.2

Introduction

This article intends to illustrate some of the ways to work with NoData and Alpha bands, with the goal of removing a black border around an image. A combination of setting NoData, setting/adding an Alpha transparency band, and/or Clipping are illustrated. The different ways in which NoData and Alpha bands can be set/added and information on the best approach per use case are provided. Note that the format chosen for writing also determines whether there is NoData or Alpha—the quick facts of each format list whether NoData values or Alpha bands are supported. The raster that will be used is shown below.

original-raster.png

The data used in this step-by-step tutorial is available in the Files section of this article.

 

Step-By-Step Instructions

In this step-by-step tutorial, you will learn how to work with NoData and Alpha bands, with the goal of removing a black border around an image in 3 different scenarios.

For the three examples below, we will use a .fmwt workspace file (removeblackborders.fmwt), which can be downloaded from the Files section.

 

Option 1: Set NoData

1. View the GeoTIFF Dataset

Click on the reader feature type and select the View Written Data... icon in the menubar that appears above it. Alternatively, you can left-click on the reader feature type and select the View Written Data... option from the context menu. Zoom into the raster image until you see it pixelated, as shown in the image below. Select a black pixel and look at the Feature Information window. All three bands are set to "0".

before-rasterbandnodata-transformer.png

 

2. Set 0 to NoData with the RasterBandNoDataSetter Transformer

The border value, which is currently black, may be set to NoData using the RasterBandNoDataSetter transformer with a NoData value set to "0". This will result in the background becoming transparent. If done this way, there is the possibility that a pixel exists in the imagery (valid data range) that is actually set to "0" for all of the bands (matching the background).

Take a look at the RasterBandNoDataSetter transformer parameters in the Set NoData bookmark. As you can see, the Nodata Value parameter is set to "0". Setting "0" to the Nodata parameter will make cells with this value transparent, which would generally be undesirable for valid data.

Select the RasterBandNoDataSetter transformer and the Run To This icon that appears over it in the menubar. Select a pixel that looks like the one in the image below and look at the Feature Information window. Those three bands from earlier have been set to "0 (Nodata)".

after-rasterbandnodata-transformer.png

For 'numeric' data, it makes more sense to use NoData because you can likely pick a value that does not exist in the imagery.

 

Option 2: Clip the Black Border

1. View the "Clip the black border" Bookmark Workflow

The black border can be removed by creating a clipper feature or using an existing vector feature to clip away the black border using the Clipper transformer. This works well if there is no extra processing down the line. If the file is to be configured (i.e., reprojected), the result could very well have a black background again, as the issue of transparency still hasn't been addressed. This method could be used for formats that don't support Alpha (transparency) or NoData bands.

If reprojection were necessary, it would make sense to reproject first using the CsmapReprojector transformer and base the clipper feature on the reprojected imagery rather than the original, as the bounds will often change.

 

2. Run the Workspace

Run the workspace only using the "Clip the black border" bookmark and its transformers from the reader to the writer feature types. In Visual Preview, we will see the image below.

after-clipping-black-border.png

 

Option 3: Set the Alpha Band and Clip the Black Border

1. View the "Set the Alpha band and Clip the black border" Bookmark Workflow

This method not only clips the black border but also adds an Alpha transparency band so that any further processing, like reprojection, doesn't cause the black border to be introduced again. This is the best method to use if the output format supports the Alpha band and if the data will be configured further in later processing.

 

2. Run the Workspace

Run the workspace only using the Alpha band and "Clip the black border" bookmark and its transformers from the reader to the writer feature types. In Visual Preview, we will see the image below.

after-clipping-and-adding-alpha-band.png

 

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.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.