-1

We need to get the Pixel value for the GeoTIFF images to calculate the mean.

In Python we use GetPixel() to know the each pixel values but which function should we use in GDAL python.

Help me Out!

kalemula aditya
  • 87
  • 1
  • 1
  • 4
  • Please, search the Web more thoroughly next time http://gis.stackexchange.com/questions/225370/get-individual-pixel-values-on-a-raster-image-using-gdal-and-python – mloskot Feb 16 '17 at 13:10

2 Answers2

1

In the simplest case you can simply use ReadAsArray() and numpy's average function:

import numpy
from osgeo import gdal

ds = gdal.Open(tiffilepath)
data = ds.ReadAsArray().astype(numpy.float32) # Type depends on the type you want for the average.
avg = numpy.average(data)
print(avg)

This statistic also likely exists in the metadata, but may not be accurate, and you may wish to calculate it differently (including/excluding no data values, background values, etc.).

Benjamin
  • 11,560
  • 13
  • 70
  • 119
1

If you want to get a limited number of pixels use gdallocationinfo

gdallocationinfo input.tif 250 150

m.zohary
  • 34
  • 2