1

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

enter image description here

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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