The GDAL utilities are command line tools of convenience for standard geoprocessing tasks but if what you want is not there then you will have to write code to call the underlying API yourself to build your own tool.
Here are a set of tutorials on using GDAL which will explain how to do what you want. However, I recommend that, unless you absolutely have to, you really don't want to loop through a raster pixel by pixel as this is very slow. This tutorial will explain why (with some bench marking) and show some better methods for some typical calculations.
When it comes to raster processing through GDAL, NumPy and SciPy are a crucial part of your coding mix (assuming you're doing this with the Python libraries of GDAL). SciPy especially has some very powerful tools for image processing. In particular have a look at scipy.ndimage
. I often just use GDAL to open or save the raster data and have NumPy or SciPy do the heavy lifting. With SciPy, for instance, I have reduced my processing time for Zonal Statistics from hours to seconds for the exact same raster and zones.
So, unless there is a pre-made GDAL Utility, you will have to write something yourself, but using built-in functions in tools like NumPy and SciPy will vastly reduce the amount of code you need to write and your processing time in preference to pixel-by-pixel iteration.
how to
here. 2. My own need is How to conditionnally assign a new value to pixels of a raster image? (gis.stackexchange.com/questions/69129), in this other question, looping through all is not necessary.