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 ...

Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.