I have one raster scene that contains one band with multiple pixel values (0-14). Each values represent deforestation in certain year (0=no tree cover loss, 1=loss in 2001, 2=loss in 2002, and so on) and I need to calculate the deforestation statistics for each years (e.g. statistics for each pixel values in that scene).

I've tried using Zonal Statistics, but it only gives me a lump of all values (total count in zonal statistic = sum of all values). What I need is to count how many pixels have value '1', '2', and so on. Any suggestion on what tool(s) to use? Properties of the scene. It only has 1 band, and it contains value of 0-14 (0=no tree loss, 1=loss in year 2001, ..., 14=loss in year 2014)

  • Can you please edit your question to expand on what you currently get and what you actually want? Add some examples or screenshots if it helps.
    – Midavalo
    May 29 '17 at 13:51
  • Clarified my question and added a screenshot of the scene properties. Hope this helps. May 29 '17 at 15:57

You can use Zonal Raster Statistics (also called Zonal Grid) tool to count the number of pixel in each class. The tool will create a new CSV file with the number of pixels for each category.

The only required parameter is the classified image (Zonal Grid) that contains the categories you want to calculate.

In the following example, I have a land use raster with 8 classes. When I run Zonal Raster Statistics tool, I got the following result:

enter image description here

Here is the output:

enter image description here

The tool can be found from Processing toolbox -> SAGA -> Geostatistics -> Zonal Raster Statistics


You might want to take a look at the SAGA Zonal Grid statistics. This is available in Processing if you have SAGA GIS installed. I've not tried this yet but it looks like it will do what you want.

According to the documentation this can create a contingency table (cross-tabulation) which includes the number of pixels ("n") in each category for each polygon.

The normal zonal statistics takes a polygon and raster layer as input.

However, this algorithm takes two (or more) raster layers instead. So you will need to convert your polygon layer to a raster layer (using Raster > Conversion > Rasterize) to use as your zonal grid, and your categorised raster as the categorical grid.

The output should be a table.


I don't really know what I'm doing with GIS but I wanted to achieve the same outcome as the OP. I'm on QGIS 3.16.0-Hannover and the existing answers didn't give me what I need (and they don't seem to live in the same spot in my version). I have a raster with a single band of values.

I found the Raster layer unique values report from the Processing Toolbox to be exactly what we're after. The description of this report is:

This algorithm returns the count and area of each unique value in a given raster layer.

In the UI, you can find it here: enter image description here

The output looks like:

Analyzed file: /vsigzip//tmp/south_australia_landcover.tif.gz (band 1)

Extent: 967587.0000000000000000,1315841.0000000000000000 : 1528884.0000000000000000,1962113.0000000000000000

Projection: GDA94 / SA Lambert

Width in pixels: 17009 (units per pixel 33)

Height in pixels: 19584 (units per pixel 33)

Total pixel count: 333104256

NODATA pixel count: 167256799

Value   Pixel count   Area (m²)
0       649033        706796937
110     11211         12208779
111     6832690       7440799410
112     1716817       1869613713
113     2899563       3157624107
114     811580        883810620
115     41014         44664246
116     374           407286
117     7973916       8683594524
...and so on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.