I have the following RGB raster and would like to remove the black background (where R=0, G=0, B=0). I'm using QGIS.

The problem is that the raster itself also contains black pixels. Using the option of QGIS to make all RGB(0,0,0) pixels transparent is therefore not an option, since it will make some of the lines transparent as well. Are there any other options?

enter image description here

  • 1
    Did you check what is the value of NODATA ?
    – Shiko
    Nov 1, 2016 at 6:42
  • The raster seems to be reprojected. Can you get hold of the unprojected source, which lets you allow to set a different NODATA value during reprojection?
    – AndreJ
    Nov 1, 2016 at 10:43

2 Answers 2


Try to use nearblack gdal utility for make raster with transparent background.

  • Those pixels are already totally black and transparent, nearblack is made for different purpose. Lossy compression methods like jpeg or ecw are sometimes changing pixel values a bit and (0 0 0) may become for example (0 1 0). Nearblack is introducing some tolerance which makes that (0 1 0) as nodata again. Useful tool but not relevant for handling this issue.
    – user30184
    Nov 11, 2015 at 10:23
  • RGB raster can not be displayed without loss (if you set NODATA to 0 0 0). Useful method - convert to RGBA and change 'frame' pixels to transparent value. Nearblack can be used for this case.
    – yellow_sky
    Nov 11, 2015 at 10:36
  • Perhaps I was wrong and nearblack may be the right tool. Have a try with -setalpha and -setmask (use -o for creating new image for output). Algorithm may be clever enough for skipping the nodata pixels within the data area.
    – user30184
    Nov 11, 2015 at 10:44

A quick-fix, though inelegant, is to create a vector layer with a polygon that matches the shape of the raster area you want. Colour the polygon black and place the new vector layer below the raster layer. Those irritating transparent pixels will be rendered over a black 'background' and will appear to be black again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.