Counting the unique values in a raster
Remotely-sensed images are not just pictures; they are data. The value of the pixels has a meaning that can be automatically analyzed by a computer. The ability to run statistical algorithms on a dataset is the key to remote sensing. This recipe counts the number of unique combinations of pixels across multiple bands. A use case for this recipe will be to assess the results of image classification, which is a recipe that we'll cover later in this chapter. This recipe is in contrast to the typical histogram function, which totals the unique values and the frequency of each value per band.
Getting ready
We will use the SatImage raster available at https://github.com/GeospatialPython/Learn/raw/master/SatImage.zip.
Place this raster in your /qgis_data/rasters
directory.
How to do it...
This algorithm relies completely on the numpy
module. Numpy can be accessed through the GDAL package's gdalnumeric
module. To do this, we need to perform the following steps:
Start...