Monday, January 11, 2021

QGIS - Change the background color of multiple raster images to transparent

QGIS can easily display geo-referenced raster images; by default the background pixels or no data value pixels are colored as black, as shown in the screenshot below. 

The black no data colored pixels can obscure other vector or raster data underneath it. You can use QGIS to define a color to be rendered as transparent in the raster layer's properties. This can be easily done for a single raster layer. If you want to do it for multiple raster layers at once, then you have to copy the style of the raster layer with a transparent color set and apply that style to the rest of the raster layers.

This post illustrates the steps.

Define the transparent color for a single raster layer

  1. Start up QGIS. Load and display the raster images.

    The raster layers are displayed with black as the background color.

  2. In the Layers pane, mouse right click on a raster layer. Choose Properties. Select Transparency.

    The Properties dialog box is displayed.

  3. In the Transparency pixel list, click the + icon.

    An RGB entry is added to the list.

  4. In the Red, Green, and Blue fields, enter 0.

  5. Click OK.

    The selected raster layer's background pixels are rendered transparent.

  6. In the Layers pane, mouse right click on the raster layer with transparent background and choose Styles | Copy Style.

  7. In the Layers pane again, press CTRL or SHIFT and select one or more raster layers.

    Multiple raster layers are selected.

  8. In the Layers pane, mouse right click on a selected raster layer and choose Paste Style.

    The selected raster layers' background is rendered transparent.