Counting number of pixels/cells with particular value in raster using ArcPy?

I have a raster image containing values ranging from 1 to 10 in Integer format.

I want to count the number of pixel with value = 1.

Is there any method in Arcpy which returns the pixel count if given raster and value as input?

Use the Build Raster Attribute Table tool, then a SearchCursor.

values = {} arcpy.BuildRasterAttributeTable_management(your_raster, "Overwrite") with arcpy.da.SearchCursor(your_raster, ['VALUE', 'COUNT']) as rows: for row in rows: values[row[0]] = row[1] print values.get(12345, 0)

Watch the video: How to Clip DEM by ArcGIS (September 2021).