title: Using GDAL and python to calculate statistics of pixel value
body: <p>I have a geotiff image created using GDAL. 
  I would like to know if it is possible using GDAL and Python (or only one of them) to extract the pixel percentage of specific value.</p>
  
  <p>In particular, if I do:</p>
  
  <pre><code>gdalinfo -hist input.tif
  </code></pre>
  
  <p>I get all the metadata info and, in particular,</p>
  
  <pre><code>Size is 4901, 2867
  ...
  Band 1 Block=4901x1 Type=Byte, ColorInterp=Palette
    Minimum=0.000, Maximum=5.000, Mean=2.263, StdDev=1.135
  0...10...20...30...40...50...60...70...80...90...100 - done.
    256 buckets from -0.5 to 255.5:
    1740973 365790 6385650 3688110 1757506 113138 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  </code></pre>
  
  <p>Is there a way to calculate the pixel percentage of the 6 values defined in the histogram? </p>
  
  <p>The size of the .tif file is 4901x2867 so if I can extract each of those fields using GDAL and/or Python then I can calculate something like this:</p>
  
  <pre><code>pixel_value_0 = 1740973/(4901x2867)
  </code></pre>
  
  <p>and get the percentage of the pixel value 0</p>