o �J�hm�@sBddlmZddlZddlmZddlmZGdd�d�ZeZdS)�)� annotationsN)�cached_property�)�Imagec@s�eZdZ dd dd �Zed!d d ��Zed"dd��Zed#dd��Zed#dd��Zed#dd��Z ed"dd��Z ed#dd��Z ed#dd��Z ed#dd��Z dS)$�StatN� image_or_list�Image.Image | list[int]�mask�Image.Image | None�return�NonecCsTt|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)�selfrr �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]]cs,d dd����fdd�td 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]cSsVd\}}td�D] }||r|}nqtddd�D] }||r&|}||fSq||fS)N)��rr r�����)r)rZres_minZres_max�irrr�minmaxMs ��zStat.extrema.<locals>.minmaxcsg|] }��j|d���qS�N)r��.0r �r!rrr� <listcomp>Ysz Stat.extrema.<locals>.<listcomp>rr N)rrr r�rrr�rrr%r�extrema>s " z Stat.extremarcs �fdd�tdt�j�d�D�S)z2Total number of pixels for each band in the image.cs"g|] }t�j||d���qS)r )�sumrr#r(rrr&^s"zStat.count.<locals>.<listcomp>rr r'r(rr(r�count[s z Stat.count� list[float]cCsRg}tdt|j�d�D]}d}td�D] }|||j||7}q|�|�q |S)z-Sum of all pixels for each band in the image.rr �)rrr�append)r�vr Z layer_sum�jrrrr*`s  zStat.sumcCsZg}tdt|j�d�D]}d}td�D]}||dt|j||�7}q|�|�q |S)z5Squared sum of all pixels for each band in the image.rr r-�)rrr�floatr.)rr/r �sum2r0rrrr3ls   z Stat.sum2c��fdd��jD�S)zAAverage (arithmetic mean) pixel level for each band in the image.cs g|] }�j|�j|�qSr)r*r+r#r(rrr&{s zStat.mean.<locals>.<listcomp>�rr(rr(r�meanx�z Stat.meancCsdg}|jD]*}d}|j|d}|d}td�D]}||j||}||kr)nq|�|�q|S)z.Median pixel level for each band in the image.rr1r )rr+rrr.)rr/r �s�half�br0rrr�median}s  � z Stat.mediancr4)z2RMS (root-mean-square) for each band in the image.cs&g|]}t��j|�j|��qSr)�math�sqrtr3r+r#r(rrr&�s&zStat.rms.<locals>.<listcomp>r5r(rr(r�rms�r7zStat.rmscr4)z$Variance for each band in the image.cs8g|]}�j|�j|d�j|�j|�qS)g@)r3r*r+r#r(rrr&�s*��zStat.var.<locals>.<listcomp>r5r(rr(r�var�s �zStat.varcr4)z.Standard deviation for each band in the image.csg|] }t��j|��qSr)r<r=r?r#r(rrr&�szStat.stddev.<locals>.<listcomp>r5r(rr(r�stddev�r7z Stat.stddevr")rrr r r r )r r)r r)r r,)�__name__� __module__� __qualname__rrr)r+r*r3r6r;r>r?r@rrrrrs* �        r) � __future__rr<� functoolsr�rr�Globalrrrr�<module>s   
Memory