
    h                    H    S SK Jr  S SKrS SKJr  SSKJr   " S S5      r\rg)    )annotationsN)cached_property   )Imagec                      \ rS rSr S     SS jjr\SS j5       r\SS j5       r\SS j5       r\SS j5       r	\SS j5       r
\SS	 j5       r\SS
 j5       r\SS j5       r\SS j5       rSrg)Stat   Nc                    [        U[        R                  5      (       a  UR                  U5      U l        O)[        U[        5      (       a  Xl        OSn[        U5      e[	        [        [        U R                  5      S-  5      5      U l        g)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       ?/var/www/html/env/lib/python3.13/site-packages/PIL/ImageStat.py__init__Stat.__init__    sf    * mU[[11",,T2DFt,,"F8CC. %DFFs 234
    c                    SS jn[        S[        U R                  5      S5       Vs/ s H  o!" U R                  US 5      PM     sn$ s  snf )a%  
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                    Su  p[        S5       H  nX   (       d  M  Un  O   [        SSS5       H  nX   (       d  M  Un  X4$    X4$ )N)   r   r   r   )r   )r   res_minres_maxis       r   minmaxStat.extrema.<locals>.minmaxM   s_    %G3Z<<G   3B'<<G##	 ( ##r   r   r   N)r   	list[int]returnztuple[int, int])r   r   r   )r   r#   r"   s      r   extremaStat.extrema>   sC    
	$ -2!S[#,FG,Fqtvvabz",FGGGs   A	c           	         [        S[        U R                  5      S5       Vs/ s H  n[        U R                  XS-    5      PM     sn$ s  snf )z2Total number of pixels for each band in the image.r   r   )r   r   r   sumr   r"   s     r   count
Stat.count[   sA     383tvv;2LM2LQDFF13w'(2LMMMs   $A
c                    / n[        S[        U R                  5      S5       H>  nSn[        S5       H  nX4U R                  X$-      -  -  nM     UR                  U5        M@     U$ )z-Sum of all pixels for each band in the image.r   r           )r   r   r   append)r   vr"   	layer_sumjs        r   r*   Stat.sum`   sa     q#dff+s+AI3Z..	  HHY	 ,
 r   c           	         / n[        S[        U R                  5      S5       HJ  nSn[        S5       H%  nX4S-  [        U R                  X$-      5      -  -  nM'     UR	                  U5        ML     U$ )z5Squared sum of all pixels for each band in the image.r   r   r/      )r   r   r   floatr0   )r   r1   r"   sum2r3   s        r   r8   	Stat.sum2l   si     q#dff+s+AD3ZAtvvae}!555  HHTN	 ,
 r   c                ~    U R                    Vs/ s H!  oR                  U   U R                  U   -  PM#     sn$ s  snf )zAAverage (arithmetic mean) pixel level for each band in the image.)r   r*   r,   r+   s     r   mean	Stat.meanx   s3     6:ZZ@Zdjjm+Z@@@s   (:c                    / nU R                    HY  nSnU R                  U   S-  nUS-  n[        S5       H  nX0R                  XV-      -   nX4:  d  M    O   UR	                  W5        M[     U$ )z.Median pixel level for each band in the image.r   r6   r   )r   r,   r   r   r0   )r   r1   r"   shalfbr3   s          r   medianStat.median}   ss     AA::a=A%DCA3Zqu%8   HHQK  r   c                    U R                    Vs/ s H6  n[        R                  " U R                  U   U R                  U   -  5      PM8     sn$ s  snf )z2RMS (root-mean-square) for each band in the image.)r   mathsqrtr8   r,   r+   s     r   rmsStat.rms   s@     BFLA		$))A,A67LLLs   =Ac                    U R                    Vs/ s HE  nU R                  U   U R                  U   S-  U R                  U   -  -
  U R                  U   -  PMG     sn$ s  snf )z$Variance for each band in the image.g       @)r   r8   r*   r,   r+   s     r   varStat.var   sa    
 ZZ
 YYq\TXXa[C/4::a=@@DJJqMQ
 	
 
s   AAc                    U R                    Vs/ s H&  n[        R                  " U R                  U   5      PM(     sn$ s  snf )z.Standard deviation for each band in the image.)r   rD   rE   rI   r+   s     r   stddevStat.stddev   s1     15

;
1		$((1+&
;;;s   -?)r   r   )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____firstlineno__r   r   r'   r,   r*   r8   r;   rA   rF   rI   rL   __static_attributes__ r   r   r   r      s    QU545<N5	5< H H8 N N 	 	 	 	 A A   M M 
 
 < <r   r   )	
__future__r   rD   	functoolsr    r   r   GlobalrT   r   r   <module>rY      s'   . #  % ~< ~<B 
r   