Ë
    ^ãjƒ  ã                  óN   — d dl mZ dhZd dlZd dlmZ ddlmZ  G d„ d«      ZeZ	y)	é    )ÚannotationsÚmathN)Úcached_propertyé   )ÚImagec                  óÄ   — e Zd Z	 d	 	 	 	 	 dd„Zedd„«       Zedd„«       Zedd„«       Zedd„«       Zedd„«       Z	edd„«       Z
edd	„«       Zedd
„«       Zedd„«       Zy)ÚStatNc                ó  — t        |t        j                  «      r|j                  |«      | _        n%t        |t        «      r|| _        nd}t        |«      ‚t	        t        t        | j                  «      dz  «      «      | _        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       úO/var/www/html/metafoliadorv2/venv/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                ó–   — dd„}t        dt        | j                  «      d«      D �cg c]  } || j                  |d «      ‘Œ c}S c c}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\  }}t        d«      D ]  }| |   sŒ	|} n t        ddd«      D ]  }| |   sŒ	|} ||fS  ||fS )N)éÿ   r   r   r   éÿÿÿÿ)r   )r   Úres_minÚres_maxÚis       r   ÚminmaxzStat.extrema.<locals>.minmaxO   so   € Ø%ÑˆG�WÜ˜3“Zò �Ø˜Q“<Ø�GÙðô ˜3  BÓ'ò �Ø˜Q“<Ø�GØØ˜GÐ#Ð#ð	ð ˜GÐ#Ð#r   r   r   N)r   ú	list[int]Úreturnztuple[int, int])r   r   r   )r   r"   r!   s      r   ÚextremazStat.extrema@   s=   € ó
	$ô -2°!´S¸¿¹³[À#Ó,FÖG q‘�t—v‘v˜a˜b�zÕ"ÒGÐGùÒGs   §Ac           	     óš   — t        dt        | j                  «      d«      D �cg c]  }t        | j                  ||dz    «      ‘Œ c}S c c}w )z2Total number of pixels for each band in the image.r   r   )r   r   r   Úsum©r   r!   s     r   Úcountz
Stat.count]   s=   € ô 38¸¼3¸t¿v¹v»;ÈÓ2LÖM¨Q”�D—F‘F˜1˜q 3™wÐ'Õ(ÒMÐMùÒMs   £"Ac                óÊ   — g }t        dt        | j                  «      d«      D ]=  }d}t        d«      D ]  }||| j                  ||z      z  z  }Œ |j                  |«       Œ? |S )z-Sum of all pixels for each band in the image.r   r   ©r   r   r   Úappend)r   Úvr!   Ú	layer_sumÚjs        r   r'   zStat.sumb   so   € ð ˆÜ�qœ#˜dŸf™f›+ sÓ+ò 	 ˆAØˆIÜ˜3“Zò /�Ø˜Q §¡¨¨A©¡Ñ.Ñ.‘	ð/à�H‰H�YÕð		 ð
 ˆr   c                óÐ   — g }t        dt        | j                  «      d«      D ]@  }d}t        d«      D ]  }||dz  | j                  ||z      z  z  }Œ |j                  |«       ŒB |S )z5Squared sum of all pixels for each band in the image.r   r   é   r+   )r   r-   r!   Úsum2r/   s        r   r2   z	Stat.sum2n   sr   € ð ˆÜ�qœ#˜dŸf™f›+ sÓ+ò 	ˆAØˆDÜ˜3“Zò /�Ø˜˜A™ §¡¨¨A©¡Ñ.Ñ.‘ð/à�H‰H�T�Nð		ð
 ˆr   c                óœ   — | j                   D �cg c]2  }| j                  |   r| j                  |   | j                  |   z  nd‘Œ4 c}S c c}w )zAAverage (arithmetic mean) pixel level for each band in the image.r   )r   r)   r'   r(   s     r   Úmeanz	Stat.meanz   sB   € ð NRÏZÉZÖXÈ¨t¯z©z¸!ª}�—‘˜‘˜dŸj™j¨™mÒ+À!ÑCÒXÐXùÒXs   �7A	c                óØ   — g }| j                   D ]X  }d}| j                  |   dz  }|dz  }t        d«      D ]  }|| j                  ||z      z   }||kD  sŒ n |j	                  «       ŒZ |S )z.Median pixel level for each band in the image.r   r1   r   )r   r)   r   r   r,   )r   r-   r!   ÚsÚhalfÚbr/   s          r   ÚmedianzStat.median   sƒ   € ð ˆØ—‘ò 	ˆAØˆAØ—:‘:˜a‘= AÑ%ˆDØ�C‘ˆAÜ˜3“Zò �Ø˜Ÿ™˜q 1™u™Ñ%�Ø�t“8Ùðð �H‰H�Q�Kð	ð ˆr   c                óÂ   — | j                   D �cg c]E  }| j                  |   r2t        j                  | j                  |   | j                  |   z  «      nd‘ŒG c}S c c}w )z2RMS (root-mean-square) for each band in the image.r   )r   r)   r   Úsqrtr2   r(   s     r   ÚrmszStat.rms�   sU   € ð
 —Z‘Zö
àð 8<·z±zÀ!²}ŒD�I‰I�d—i‘i ‘l T§Z¡Z°¡]Ñ2Ô3È!ÑKò
ð 	
ùò 
s   �A
Ac                óâ   — | j                   D �cg c]U  }| j                  |   rB| j                  |   | j                  |   dz  | j                  |   z  z
  | j                  |   z  nd‘ŒW c}S c c}w )z$Variance for each band in the image.r1   r   )r   r)   r2   r'   r(   s     r   ÚvarzStat.var—   st   € ð —Z‘Zö
ð ð —:‘:˜a’=ð —‘˜1‘ §¡¨!¡°Ñ!1°T·Z±ZÀ±]Ñ BÑBÀdÇjÁjÐQRÁmÒSàñò
ð 	
ùò 
s   �AA,c                ó€   — | j                   D �cg c]$  }t        j                  | j                  |   «      ‘Œ& c}S c c}w )z.Standard deviation for each band in the image.)r   r   r;   r>   r(   s     r   ÚstddevzStat.stddev£   s-   € ð 15·
±
Ö;¨1”—	‘	˜$Ÿ(™( 1™+Õ&Ò;Ð;ùÒ;s   �);)N)r   zImage.Image | list[int]r   zImage.Image | Noner$   ÚNone)r$   zlist[tuple[int, int]])r$   r#   )r$   zlist[float])Ú__name__Ú
__module__Ú__qualname__r   r   r%   r)   r'   r2   r4   r9   r<   r>   r@   © r   r   r	   r	   !   sÜ   „ àQUð5Ø4ð5Ø<Nð5à	ó5ð< òHó ðHð8 òNó ðNð ò	ó ð	ð ò	ó ð	ð òYó ðYð òó ðð ò
ó ð
ð ò	
ó ð	
ð ò<ó ñ<r   r	   )
Ú
__future__r   Ú__lazy_modules__r   Ú	functoolsr   Ú r   r	   ÚGlobalrE   r   r   ú<module>rK      s/   ðõ. #à�8Ð ã Ý %å ÷E<ñ E<ðP 
�r   