First of all, to actually run a saga processing scrip use
processing.runalg("saga:algorithmname", parameter1, parameter2)
Basically Qgis can do two things:
(1) Perform mathematical operations with rasters -> use saga raster calculator from processing toolbox
A thing that can help you is that you can refer to the grids as a,b,c etc. a+b will add two grids.
(2) perform logical tests e.g. raster "value" > 10 -> use QgsRasterCalculator from Qgis.analysis
The script below will execute a simple test. I believe you can use SQL Query within the Python code.
from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry
# Add raster
rasterpath = "/Desktop/werkmap/CHIRPS/chirps-v1.8.2012.01.tif"
bohLayer = QgsRasterLayer(rasterpath, "rasterlayername")
if not bohLayer.isValid():
print "Layer failed to load!"
# Load raster layer into canvas (not required for script but hey it looks awesome)
QgsMapLayerRegistry.instance().addMapLayer(bohLayer)
entries = []
# Define band1
boh1 = QgsRasterCalculatorEntry()
boh1.ref = 'boh@1'
boh1.raster = bohLayer
boh1.bandNumber = 1
entries.append( boh1 )
# repeat step above if multiple bands
# Process calculation with input extent and resolution
calc = QgsRasterCalculator( 'boh@1 > 10', '/Desktop/werkmap/output/outputfile.tif', 'GTiff', bohLayer.extent(), bohLayer.width(), bohLayer.height(), entries )
calc.processCalculation()
print "finish"
Try setting the raster data type - such as gdal.GDT_Float32
dsOut = driver.Create(outFile, g.RasterXSize, g.RasterYSize, 1, gdal.GDT_Float32)
Best Answer
In python (with numpy, assuming "naip" is your 4 band image as a numpy array), the following will rescale your data to 0-255 in reverse:
If your data is already >0 and <255 and you don't want to scale it from 0-255, but just reverse it:
An ArcGIS raster calculator solution would be quite similar, though you would have to operate on the bands individually then combine them again afterwards.