ImageStat module¶
The ImageStat module calculates global statistics for an image, or
for a region of an image.
- class PIL.ImageStat.Stat(image_or_list: Image | list[int], mask: Image | None = None)[source]¶
- __init__(image_or_list: Image | list[int], mask: Image | None = None) None[source]¶
Calculate statistics for the given image. If a mask is included, only the regions covered by that mask are included in the statistics. You can also pass in a previously calculated histogram.
- Parameters:
image –
A PIL image, or a precalculated histogram.
Note
For a PIL image, calculations rely on the
histogram()method. The pixel counts are grouped into 256 bins, even if the image has more than 8 bits per channel. SoIandFmode images have a maximummean,medianandrmsof 255, and cannot have anextremamaximum of more than 255.mask – An optional mask.
- property extrema: list[tuple[int, int]][source]¶
Min/max values for each band in the image.
Note
This relies on the
histogram()method, and simply returns the low and high bins used. This is correct for images with 8 bits per channel, but fails for other modes such asIorF. Instead, usegetextrema()to return per-band extrema for the image. This is more correct and efficient because, for non-8-bit modes, the histogram method usesgetextrema()to determine the bins used.