QGIS Raster – Extracting Pixel Value Counts from a Raster in QGIS

qgisraster

How does one go about obtaining a summary of the counts of cell values within a raster in QGIS? I know QGIS is doing this, in order to provide the summary statistics and histogram in the properties of the layer. I do not need the summary statistics nor a histogram image, but rather counts of individual values.

It looks like there was at one point an attempt to add a special feature for this (Feature #4321, http://hub.qgis.org/issues/4321).

Am I missing something really obvious?

Best Answer

r.report from GRASS in the Processing toolbox lets you get a count if you set the Units to c.

getting count of raster values with r.report in qgis processing with grass

Results in (this includes NoData represented as int 0):

+-----------------------------------------------------------------------------+ 
| Category Information | cell| 
| #|description | count| 
|-----------------------------------------------------------------------------| 
|  0| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |147600504| 
| 10| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 46945| 
| 20| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 34371070| 
| 30| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 38494918| 
| 34| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 3542216| 
| 50| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 37053253| 
| 80| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 24184039| 
|110| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 8622768| 
|120| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 4279049| 
|122| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 3126056| 
|131| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 786| 
|133| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 452832| 
|136| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 29765| 
|137| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 317| 
|140| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 1725632| 
|147| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 130470| 
|153| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 1153795| 
|162| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 125372| 
|167| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 176| 
|175| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 36144| 
|181| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 160465| 
|188| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 50| 
|194| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 4854| 
|210| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |257580769| 
|220| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 35232865| 
|230| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 6891335| 
|-----------------------------------------------------------------------------| 
|TOTAL |604846445| 
+-----------------------------------------------------------------------------+

Taken from: example raster with paletted band