2013-10-14 08:57:07 +04:00
|
|
|
.. py:module:: PIL.ImageStat
|
|
|
|
.. py:currentmodule:: PIL.ImageStat
|
|
|
|
|
2020-06-22 06:52:50 +03:00
|
|
|
:py:mod:`~PIL.ImageStat` Module
|
|
|
|
===============================
|
2013-10-14 08:57:07 +04:00
|
|
|
|
2020-06-22 06:52:50 +03:00
|
|
|
The :py:mod:`~PIL.ImageStat` module calculates global statistics for an image, or
|
2013-10-14 08:57:07 +04:00
|
|
|
for a region of an image.
|
|
|
|
|
2020-06-14 18:16:15 +03:00
|
|
|
.. py:class:: Stat(image_or_list, mask=None)
|
2013-10-14 08:57:07 +04:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
:param image: A PIL image, or a precalculated histogram.
|
2022-03-02 13:21:25 +03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
For a PIL image, calculations rely on the
|
|
|
|
:py:meth:`~PIL.Image.Image.histogram` method. The pixel counts are
|
|
|
|
grouped into 256 bins, even if the image has more than 8 bits per
|
|
|
|
channel. So ``I`` and ``F`` mode images have a maximum ``mean``,
|
|
|
|
``median`` and ``rms`` of 255, and cannot have an ``extrema`` maximum
|
|
|
|
of more than 255.
|
|
|
|
|
2013-10-14 08:57:07 +04:00
|
|
|
:param mask: An optional mask.
|
|
|
|
|
|
|
|
.. py:attribute:: extrema
|
|
|
|
|
|
|
|
Min/max values for each band in the image.
|
|
|
|
|
2019-08-03 16:24:28 +03:00
|
|
|
.. note::
|
|
|
|
|
2020-06-14 18:16:15 +03:00
|
|
|
This relies on the :py:meth:`~PIL.Image.Image.histogram` method, and
|
2019-08-03 16:24:28 +03:00
|
|
|
simply returns the low and high bins used. This is correct for
|
2019-07-07 03:12:09 +03:00
|
|
|
images with 8 bits per channel, but fails for other modes such as
|
2020-06-14 18:16:15 +03:00
|
|
|
``I`` or ``F``. Instead, use :py:meth:`~PIL.Image.Image.getextrema` to
|
2019-07-07 03:12:09 +03:00
|
|
|
return per-band extrema for the image. This is more correct and
|
|
|
|
efficient because, for non-8-bit modes, the histogram method uses
|
2020-06-14 18:16:15 +03:00
|
|
|
:py:meth:`~PIL.Image.Image.getextrema` to determine the bins used.
|
2019-02-17 16:06:29 +03:00
|
|
|
|
2013-10-14 08:57:07 +04:00
|
|
|
.. py:attribute:: count
|
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
Total number of pixels for each band in the image.
|
2013-10-14 08:57:07 +04:00
|
|
|
|
|
|
|
.. py:attribute:: sum
|
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
Sum of all pixels for each band in the image.
|
2013-10-14 08:57:07 +04:00
|
|
|
|
|
|
|
.. py:attribute:: sum2
|
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
Squared sum of all pixels for each band in the image.
|
2013-10-14 08:57:07 +04:00
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
.. py:attribute:: mean
|
2013-10-14 08:57:07 +04:00
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
Average (arithmetic mean) pixel level for each band in the image.
|
2013-10-14 08:57:07 +04:00
|
|
|
|
|
|
|
.. py:attribute:: median
|
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
Median pixel level for each band in the image.
|
2013-10-14 08:57:07 +04:00
|
|
|
|
|
|
|
.. py:attribute:: rms
|
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
RMS (root-mean-square) for each band in the image.
|
2013-10-14 08:57:07 +04:00
|
|
|
|
|
|
|
.. py:attribute:: var
|
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
Variance for each band in the image.
|
2013-10-14 08:57:07 +04:00
|
|
|
|
|
|
|
.. py:attribute:: stddev
|
|
|
|
|
2014-07-15 01:44:12 +04:00
|
|
|
Standard deviation for each band in the image.
|