Creating a raster composite from separate bands in QGIS

02.06.2011 13:24 ·  GIS  ·  qgis, howto

Often, novice QGIS users who have downloaded satellite images from Earth Explorer or other sources ask themselves: “What do I do with these files, and why do I see a black rectangle or a black and white image instead of a nice color image?” The thing is that satellite images are usually distributed as separate files, each of which corresponds to a specific radiation range (channel). To get a beautiful and informative image, these channels (often called bands) should be combined, and then, depending on the task, we need to choose the right band combination.

In this post I will show you how to do this in QGIS. I will assume that QGIS is already installed and that you already have a set of rasters that make up a multi-band image, such as a Landsat scene.

Preparation

For this task we need the GdalTools plugin, which has been included with QGIS since version 1.5.0. To make sure the plugin is installed, go to the “Plugins → Manage Plugins” menu and look for the GdalTools plugin in the Plugin Manager dialog. If the plugin is present but not enabled, you should enable it.

If the plugin is not in the list of available plugins, you need to install it. To do this:

  1. Open the Plugin Installer from the “Plugins → Fetch Python Plugins…” menu
  2. In the Plugin Installer window, select the Repositories tab and verify that the Faunalia repository is added. If the repository is on the list, go to step 4.
  3. If the repository is not there, click the “Add 3rd party repositories” button, read the warning, and take note. Go to the “Options” tab and in the “Allowed plugins” group, activate the checkbox “Show all plugins, even those marked as experimental”.
  4. Go to the “Plugins” tab and use the filter to find the GdalTools plugin in the list, select it and click “Install Plugin”.
  5. Wait while QGIS downloads and installs the plugin. After successful installation, the plugin will be activated automatically.
  6. The enabled plugin creates a “Raster” entry in the QGIS main menu if it does not already exist or adds its tools to the existing menu.
    GdalTools entries in the Raster menu
    GdalTools entries in the Raster menu

Creating raster composite

Suppose we have a Landsat scene in the form of rasters representing individual image channels, 7 files in total. We need to get one file with 7 bands.

To make things easier, let’s put all 7 files into a single folder. The set of files might look like this

Files of the Landsat scene
Files of the Landsat scene

Depending on the type of Landsat scene, there may also be a much larger *_B80 file.

Go to the “Raster” menu, select “Merge”, and start filling in the dialogue box that opens:

The “Creation Options” group is worth mentioning separately. With its help, you can fine-tune the output file creation, e.g., enable compression, create world file, etc. Each output format has its own set of possible parameters, and you can check them out on the corresponding format page (list of supported formats).

For example, you can set the following parameters for the TIFF format COMPRESS=LZW, TILED=YES, TFW=YES, BIGTIFF=IF_NEEDED. This will enable Lempel-Ziv-Welch compression, force QGIS to create a world file, enable BIGTIFF mode if needed (if the file is larger than 4 GB), and create the tiled image, which in some cases increases loading and rendering speed.

Defining creation options
Defining creation options

In general, the use of additional parameters requires a preliminary study, as the parameters optimal for some tasks may be unacceptable for others. At the end of the post, there is a link to a small study of different compression algorithms. So I would not recommend setting any additional creation options unless you have specific requirements and know what you are doing.

Once you have filled in all the required fields, click on the OK button and wait for the merge process to be completed.

Note that at the bottom of the dialogue box, there is a field containing the GDAL command used to perform the operation. It can be copied, edited, and executed separately if needed.

Viewing image

After combining the individual bands, we have a multi-band raster that we can now visualise.

By default, QGIS opens multiband rasters using the default 1-2-3 band combination, which is not always convenient (see this post for more details on how to change this behaviour). You can change the band combination and some other parameters that affect how the raster is displayed in the “Layer Properties” dialogue box (accessible from the layer context menu).

The band combination and contrast enhancement algorithm are set in the “Style” tab of the “Layer Properties” dialogue box.

Adjusting band combination and contrast enhancement
Adjusting band combination and contrast enhancement

Below, you can see the same raster in QGIS with different band combinations and contrast enhancement algorithm.

Left: 1-2-3 band combination, no contrast enchancement; right: 5-4-3 band combination, stretch to min-max contrast enchancement
Left: 1-2-3 band combination, no contrast enchancement; right: 5-4-3 band combination, stretch to min-max contrast enchancement

In the same window, on the “Transparency” tab, you can specify which raster values to use as NODATA. In our example, the black areas around the image have a value of 0 (zero), so to remove them, we set 0 as the ‘No data’ value.

Defining NODATA value for raster
Defining NODATA value for raster

Now, our raster is displayed without any black areas, which is particularly useful when you need to display several overlapping scenes.

Landsat scene with applied NODATA value
Landsat scene with applied NODATA value

For those who would like to learn more about different raster compression options and Landsat band combinations, I suggest the following links as a starting point:

⮜ Prev
Next ⮞