ImageStat Module

The ImageStat module calculates global statistics for an image, orfor a region of an image.

  • class PIL.ImageStat.Stat(image_or_list, mask=None)
  • Calculate statistics for the given image. If a mask is included,only the regions covered by that mask are included in thestatistics. You can also pass in a previously calculated histogram.

Parameters:

  • image – A PIL image, or a precalculated histogram.
  • mask – An optional mask.
  • extrema
  • Min/max values for each band in the image.

Note

This relies on the histogram() method, andsimply returns the low and high bins used. This is correct forimages with 8 bits per channel, but fails for other modes such asI or F. Instead, use getextrema() toreturn per-band extrema for the image. This is more correct andefficient because, for non-8-bit modes, the histogram method usesgetextrema() to determine the bins used.

  • count
  • Total number of pixels for each band in the image.

  • sum

  • Sum of all pixels for each band in the image.

  • sum2

  • Squared sum of all pixels for each band in the image.

  • mean

  • Average (arithmetic mean) pixel level for each band in the image.

  • median

  • Median pixel level for each band in the image.

  • rms

  • RMS (root-mean-square) for each band in the image.

  • var

  • Variance for each band in the image.

  • stddev

  • Standard deviation for each band in the image.