o
�J�hm � @ sB d dl mZ d dlZd dlmZ ddlmZ G dd� d�ZeZdS )� )�annotationsN)�cached_property� )�Imagec @ s� e Zd Z dd dd �Zed!dd��Zed"dd��Zed#dd��Zed#dd��Zed#dd��Z ed"dd��Z
ed#dd��Zed#dd��Zed#dd��Z
dS )$�StatN�
image_or_list�Image.Image | list[int]�mask�Image.Image | None�return�Nonec C sT t |tj�r
|�|�| _nt |t�r|| _nd}t|��ttt| j�d ��| _dS )a
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.
.. 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.
:param mask: An optional mask.
z$first argument must be image or list� N) �
isinstancer � histogram�h�list� TypeError�range�len�bands)�selfr r �msg� r �KC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\PIL\ImageStat.py�__init__ s
z
Stat.__init__�list[tuple[int, int]]c s, ddd�� � �fdd�t d t�j�d
�D �S )
au
Min/max values for each band in the image.
.. note::
This relies on the :py:meth:`~PIL.Image.Image.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 as
``I`` or ``F``. Instead, use :py:meth:`~PIL.Image.Image.getextrema` to
return per-band extrema for the image. This is more correct and
efficient because, for non-8-bit modes, the histogram method uses
:py:meth:`~PIL.Image.Image.getextrema` to determine the bins used.
r � list[int]r �tuple[int, int]c S sV d\}}t d�D ]
}| | r|} nqt ddd�D ]
}| | r&|} ||fS q||fS )N)�� r r
r �����)r )r Zres_minZres_max�ir r r �minmaxM s ��zStat.extrema.<locals>.minmaxc s g | ]}� �j |d � ��qS �N)r ��.0r �r! r r r �
<listcomp>Y s z Stat.extrema.<locals>.<listcomp>r r
N)r r r r �r r r �r r r% r �extrema>