Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/PIL/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/PIL/__pycache__/ImageStat.cpython-312.pyc

�

&ٜg���H�ddlmZddlZddlmZddlmZGd�d�ZeZy)�)�annotationsN)�cached_property�)�Imagec���eZdZ	d					d
d�Zedd��Zedd��Zedd��Zedd��Zedd��Z	edd��Z
edd	��Zedd
��Zedd��Z
y)�StatNc��t|tj�r|j|�|_n%t|t�r||_n
d}t|��t	t
t|j�dz��|_y)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)�self�
image_or_list�mask�msgs    �8/usr/local/lib/python3.12/site-packages/PIL/ImageStat.py�__init__z
Stat.__init__ sb��*�m�U�[�[�1�"�,�,�T�2�D�F�
�
�t�
,�"�D�F�8�C��C�.� ��%��D�F�F��s� 2�3�4��
�c��dd�}tdt|j�d�D�cgc]}||j|d���c}Scc}w)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.
        c��d\}}td�D]}||s�	|}ntddd�D]}||s�	|}||fS||fS)N)�rr
r���)r)r�res_min�res_max�is    r�minmaxzStat.extrema.<locals>.minmaxMse��%��G�W��3�Z���Q�<��G�� ��3��B�'���Q�<��G���G�#�#�	(��G�#�#rrr
N)r�	list[int]�returnztuple[int, int])rrr
)rr!r s   r�extremazStat.extrema>sC��
	$�-2�!�S����[�#�,F�G�,F�q��t�v�v�a�b�z�"�,F�G�G��Gs�Ac	��tdt|j�d�D�cgc]}t|j||dz���c}Scc}w)z2Total number of pixels for each band in the image.rr
)rrr
�sum�rr s  r�countz
Stat.count[sC��38��3�t�v�v�;��2L�M�2L�Q��D�F�F�1�q�3�w�'�(�2L�M�M��Ms�"Ac���g}tdt|j�d�D]=}d}td�D]}|||j||zzz
}�|j|��?|S)z-Sum of all pixels for each band in the image.rr
�)rrr
�append)r�vr �	layer_sum�js     rr&zStat.sum`se��
���q�#�d�f�f�+�s�+�A��I��3�Z���Q�����A���.�.�	� �
�H�H�Y��	,�
�rc	���g}tdt|j�d�D]I}d}td�D]&}||dzt|j||z�zz
}�(|j	|��K|S)z5Squared sum of all pixels for each band in the image.rr
r*�)rrr
�floatr+)rr,r �sum2r.s     rr2z	Stat.sum2lsm��
���q�#�d�f�f�+�s�+�A��D��3�Z����A���t�v�v�a�!�e�}�!5�5�5�� �
�H�H�T�N�	,�
�rc�z�|jD�cgc]!}|j||j|z��#c}Scc}w)zAAverage (arithmetic mean) pixel level for each band in the image.)rr&r(r's  r�meanz	Stat.meanxs5��6:�Z�Z�@�Z�������d�j�j��m�+�Z�@�@��@s�&8c���g}|jD]X}d}|j|dz}|dz}td�D]}||j||zz}||kDs�n|j	��Z|S)z.Median pixel level for each band in the image.rr0r
)rr(rr
r+)rr,r �s�half�br.s       r�medianzStat.median}sy��
�����A��A��:�:�a�=�A�%�D��C��A��3�Z������q�1�u�
�%���t�8�� �
�H�H�Q�K���rc��|jD�cgc]4}tj|j||j|z���6c}Scc}w)z2RMS (root-mean-square) for each band in the image.)r�math�sqrtr2r(r's  r�rmszStat.rms�s@��BF���L��A��	�	�$�)�)�A�,����A��6�7��L�L��Ls�9Ac��|jD�cgc]D}|j||j|dz|j|zz
|j|z��Fc}Scc}w)z$Variance for each band in the image.g@)rr2r&r(r's  r�varzStat.var�sa��
�Z�Z�
����Y�Y�q�\�T�X�X�a�[�C�/�4�:�:�a�=�@�
@�D�J�J�q�M�Q��
�	
��
s�A	Ac��|jD�cgc]$}tj|j|���&c}Scc}w)z.Standard deviation for each band in the image.)rr;r<r?r's  r�stddevzStat.stddev�s1��15�
�
�;�
�1��	�	�$�(�(�1�+�&�
�;�;��;s�);)N)rzImage.Image | list[int]rzImage.Image | Noner#�None)r#zlist[tuple[int, int]])r#r")r#zlist[float])�__name__�
__module__�__qualname__rrr$r(r&r2r4r9r=r?rA�rrrrs���QU�5�4�5�<N�5�	
�5�<�H��H�8�N��N��	��	��	��	��A��A��
��
��M��M��
��
��<��<rr)	�
__future__rr;�	functoolsr�rr�GlobalrFrr�<module>rKs'��.#��%��~<�~<�B
�r

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists