# Multiband Raster Reclassification in QGIS

I have a raster which nodata is 0,0,0 in all three bands, how can I reclassify them into 255,255,255?

QGIS Raster Calculator returns only one image at a time, so you need to calculate it for each band.

# Band1
(BM24_10K_0501@1 = 0) * (BM24_10K_0501@2 = 0) * (BM24_10K_0501@3 = 0) * 255
+ (((BM24_10K_0501@1 > 0) + (BM24_10K_0501@2 > 0) + (BM24_10K_0501@3 > 0))>0) * BM24_10K_0501@1

This may look complicated;

• When the cell is RGB(0,0,0), the first line becomes (0=0)*(0=0)*(0=0)*255, which means True*True*True*255 or 1*1*1*255. So it outputs cell value 255.
• At the same time the second line becomes ((0>0)+(0>0)+(0>0))>0*band1, which means ((False+False+False)>0)*band1 or (0+0+0)>0*band1. So it returns zero.
• Overall, this expression replaces Band1= 0 by 255 if input cells are RGB(0,0,0).

Repeat this for Band 2 and Band 3:

# Band2
(BM24_10K_0501@1 = 0) * (BM24_10K_0501@2 = 0) * (BM24_10K_0501@3 = 0) * 255
+ (((BM24_10K_0501@1 > 0) + (BM24_10K_0501@2 > 0) + (BM24_10K_0501@3 > 0))>0) * BM24_10K_0501@2
# Band3
(BM24_10K_0501@1 = 0) * (BM24_10K_0501@2 = 0) * (BM24_10K_0501@3 = 0) * 255
+ (((BM24_10K_0501@1 > 0) + (BM24_10K_0501@2 > 0) + (BM24_10K_0501@3 > 0))>0) * BM24_10K_0501@3

Final step: Merge these new rasters into single raster.

If you dont want to work with raster calculator you can do this task by using Reclassify values (simple) from SAGA processing toolbox.

Choose Grid value equals low value as condition and create a lookup table with lowest and highest value 0 to be replaced by 255. This will not touch your other values (means no need to enter the whole table from 0 to 254).

Do this for all 3 bands, e.g. by using batch processing.

PS: just tried with reclassify by table (non SAGA) with no success, no idea why. However, the SAGA tool works just fine.