I have a raster which nodata is 0,0,0 in all three bands, how can I reclassify them into 255,255,255?
Asked
Active
Viewed 1,815 times
1
-
1Have you tried playing around with the 'Raster Calculator' under the Raster dropdown menu? (see e.g. http://gis.stackexchange.com/questions/27988/how-to-reclassify-in-rastercalc). You can also use GRASS under Processing -> Toolbox (see e.g. http://gis.stackexchange.com/questions/121532/how-to-reclass-a-raster-with-reclassify-grid-values-in-qgis). – weiji14 Jan 04 '17 at 01:25
-
Also, take a look at this: http://www.lutraconsulting.co.uk/blog/2016/09/05/serval/ – Albert Jan 04 '17 at 11:40
2 Answers
1
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 meansTrue*True*True*255or1*1*1*255. So it outputs cell value255. - At the same time the second line becomes
((0>0)+(0>0)+(0>0))>0*band1, which means((False+False+False)>0)*band1or(0+0+0)>0*band1. So it returns zero. - Overall, this expression replaces Band1=
0by255if 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.
Kazuhito
- 30,746
- 5
- 69
- 149
0
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.
MrXsquared
- 34,292
- 21
- 67
- 117

