Making RGB Images with Sentinel Data

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

This article will run you through the process of creating an RGB image from single-band raster images collected by Sentinel-2 with FME. Using these bands we’ll create the RGB image, brighten it, then also create a near-infrared image by switching the bands. Finally, we’ll show you how to create a 3D surface with the satellite image draped over a Digital Elevation Model by taking advantage of the AWS hosted Mapzen global Digital Elevation Model (DEM).
  

Step-by-step Instructions

This example uses data from the USGS Earth Explorer online app. It does however require the user to sign up for a free account and then download the Bulk Downloader application. To save the steps, we have downloaded and provided the data for you. 
 

Part 1: Create an RGB Image

1.  Open FME Workbench
Open FME Workbench and start a blank workspace. Add a JPEG 2000 reader to the canvas and then browse to the folder with the Sentinel files. Select all four files, then open the Parameters. 
JpegReader.png

In the Parameters, set the Feature Type Name(s) to From File Name(s), then click OK twice to finish adding the reader. This step is important as it ensures that each band has its own reader feature type which we can use to change band order later on. 
jpegParams.png

Finally, in the Select Feature Type dialog, ensure all four images are selected then click OK. 
 
2. Inspect a Band
So we have an idea of what our data looks like before we continue, let’s inspect the B02 band. Single-click on the reader feature type to open the popup menu and then click on View Source Data to view the data in Visual Preview. These images are very large so it may take a while to load. After inspecting this band, be sure to turn off Run with Feature Caching and use an Inspector after any transformer that you wish to view. These files are very large and will take a long time to run if feature caching is turned on. 
InspectB2.png

These images are very dark. If you open the Feature Information Window, you’ll notice that the pixel values and interpretation are GRAY16. We in the next few steps we’ll work on brightening these and combining them with other bands. 
 
3. Change Band Interpretation 
Let’s create a full-color image. The first thing we will need to do is change the band interpretation for each band since they are all in GREY16. Add a RasterBandInterpretationCoercer to the canvas and connect it to the B02 reader feature type. In the parameters change the Destination Interpretation Type to Blue16, we can accept the defaults for the other parameters. 
RBICB2.png
 
Add another RasterBandInterpretationCoercer to the canvas and connect it to the B03 reader feature type, set the Destination Interpretation Type to Green. Finally, add a third RasterBandInterpretationCoercer and connect it to the B04 reader feature type, then set it to Red. 
RasterCoecerConnections.png

 
4. Combine Bands
Now with each of the bands colored, let’s combine them. Add a RasterBandCombiner transformer to the canvas and connect all three of the RasterBandInterpretationCoercers. We can accept the default parameters for this transformer. 
Now if you run the workspace and then inspect the output you’ll notice that the raster is still very dark, but it is in color. This is because bands contain information about how much light each pixel on the sensor received, the values are not currently stretched to the whole available range of 16-bit. 
Note: If the RasterBandCombiner failed, there may be an issue with the number of rows/columns that each raster has. Use the Feature Information window to review the total number of each to confirm that they are the same across all bands. 
 
5. Create Multiplier Parameter
Since we want to brighten each band by the same value, let’s create a published parameter to make this easy to change and adjust. In the Navigator pane, right-click on User Parameters then select Manage User Parameters. 
ManageUserParams.png
 
In the User Parameter dialog, click on the green plus sign (+) and select Number as the parameter type. Next, set the following parameter properties:

  • Parameter Identifier: MULTIPLIER
  • Prompt: Color Correction:
  • Published: Enabled
  • Required: Enabled
  • Disable Attribute Assignment: Disabled
  • Lower Limit: Greater than value
  • Value: 0
  • Upper Limit: None
  • Number Precision: Integer
  • Default Value: 5

MuliplierParam.png
Click OK to save the parameter. 
 
6. Brighten Image
We will use a raster expression to brighten the image. Add a RasterExpressionEvaluator to the canvas and connect it to the RasterBandCombiner. In the parameters, set the Interpretation to Red8, then click on the ellipsis for Expression to open the Arithmetic Editor. In the Arithmetic Editor, expand Raster Bands, and double-click on A[]. Then where it says <INDEX> enter 0. Next, add a multiplication symbol (*) then expand User Parameters and double-click on MULTIPLIER. Finally divide (/) the entire equation by 255, which is 8 bits in binary:

A[0]*$(MULTIPLIER)/255

ArithmeticEditor.png

Next, create two more interpretations:

Interpretation Expression
Green8 A[1]*$(MULTIPLIER)/255
Blue8 A[2]*$(MULTIPLIER)/255


This will increase the brightness of the pixels and change the interpretation of each band from 16-bit to 8-bit. The MULTIPLIER determines how much brighter to make the pixels. We are dividing by 255 to get the pixel values into the 8-bit range. 8-bit color bands can have pixel values up to 255 (or 2^8-1) whereas 16-bit color bands can have values up to 65535 (or 2^16-1).
ExpressionEval.png
Now if you run the workspace, you may get the correct image, or it may be very white. This is due to the bands being out of order. Note if you get a Translation Error, ensure that each expression is only a single line. 
 
7. Create Sort Order
Let’s ensure that the bands are always read in the correct order to fix our image. Add an AttributeCreator after each of the RasterBandInterpretationCoercers. In the parameters, create a new attribute called _sort, then for the AttributeCreator attached to the Red band (B04), give it the value of 1. For Green (B03) a value of 2, then for Blue (B02) a value of 3. 
AttributeCreator.png
AttributeCreatorConnections.png
 
8. Sort
Finally, let’s sort the bands so that they appear in the correct order. Add a Sorter to the canvas and connect it before the RasterBandCombiner, but attached to all three AttributeCreators. In the parameters, set the Attribute to _sort, then numerically sort by descending. 
Sorter.png
 
9. Run Workspace
Run the workspace and inspect the output of the RasterExpressionEvaluator. After sorting the bands, the output should look pretty good. You can try adjusting the multiplier for even better results. Real color balancing requires much more which isn’t covered in this tutorial.  
OutputRGB.png
 

Part 2: Creating an Infrared Image

10. Connect Band 8
It’s really easy to create an infrared image since we already did the bulk of the work to create the RGB image. The only thing we need to change is the connections. Disconnect/disable the Blue reader feature type (B02), then connect the Green reader feature type (B03) to the Blue RasterBandInterpretationCoercer. Then connect the Red reader feature type (B04) to the Green RasterBandInterpretationCoercer. Finally, connect the Infrared reader feature type (B08) to the Red RasterBandInterpretationCoercer. Here we are sort of shifting all of the data higher in the visible spectrum.
NIRConnections.png
 
11. Run the Workspace
Run the workspace and view the output. If the image has a lot of forests and other vegetation, you should see a lot of red as trees reflect a lot of infrared light. In the next tutorial, we will use the NIR band to calculate a Normalized Difference Vegetation Index (NDVI). 
NIROutput.png
 

Part 3: Create a 3D Surface

12. Download DEM
We will use the MapzenAWSDEMDownloader from the FME Hub to download a DEM. Add a MapzenAWSDEMDownloader to the canvas then connect it after the RasterExpressionEvaluator. It is important here that the image you are using has a coordinate system otherwise the workspace will fail. 
ConnectMapzen.png

In the parameters, set the DEM Zoom Level to 10, then set the Number of Tiles to 50. If you get an error when running the translation, you’ll need to increase the number of tiles. 

13. Run Workspace 
Add an Inspector transformer after the MapzenAWSDEMDownloader, then run the workspace. View the output in Visual Preview, you should have a black and white Digital Elevation Model (DEM). 
DEM.png
 
14. Generate TIN Surface
Now we need to generate a TIN surface on which we can drape the satellite image. Add a TINGenerator to the canvas and connect the Points/Lines input port to the MapzenAWSDEMDownloader output port. 
TINConnection.png

In the parameters, set the Surface Tolerance to 305.75. This number is listed in the MapzenAWDDEMDownloader next to the zoom level. If you changed the zoom level, this number will be different. 
TinParams.png
 
15. Scale Image
Before we can drape the image, we need to exaggerate the vertical component of the TIN surface. Add a Scaler to the canvas and connect it to the TIN Surface output port. In the parameters, set the Z Scale Factor to 2.5. If you are in a very flat area, you can set this to 10. 
Scaler.png
 
16. Drape Image
Finally, we can drape the satellite image over our DEM. Add an AppearanceSetter to the canvas, connect the RasterExpressionEvaluator Results output port to the Appearance input port on the AppearanceSetter. Next, connect the Scaler to the Geometry input port. 
AppearanceSetter.png

In the parameters, expand the Texture Coordinate Generation Parameters section, then set the Texture Mapping Type to From Top View. 
AppearanceSetterParams.png
 
17. Run Workspace
Connect an Inspector to the Output port on the AppearenceSetter then run the workspace. View the output in Visual Preview. This example is still using the NIR image, but you could switch the band order back for an RGB image if you wish. 
3DOutput.png
 
Optionally, you could write this out to an OBJ format and view the dataset using FMEAR
 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.