)EjPddlmZddlZddlmZddlmZGddZeZdS)) annotationsN)cached_property)ImageceZdZ dddZedd Zedd ZeddZeddZeddZ eddZ eddZ eddZ eddZ dS)StatN image_or_listImage.Image | list[int]maskImage.Image | NonereturnNonec8t|tjr|||_n.t|tr||_nd}t |t t t|jdz|_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 listN) isinstancer histogramhlist TypeErrorrangelenbands)selfr r msgs ?C:\PYTHON\MyICR_Suite\python\Lib\site-packages\PIL/ImageStat.py__init__z Stat.__init__ s* mU[ 1 1 !",,T22DFF  t , , !"DFF8CC.. %DF s 23344 list[tuple[int, int]]cnd dfdtdtjdDS) 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]cd\}}tdD]}||r|}ntdddD]}||r|}n||fS)N)rrr#)r)rres_minres_maxis rminmaxzStat.extrema..minmaxMs% GW3ZZ  Q<GE3B''  Q<GEG# #rc@g|]}j|dSN)r).0r'r(rs r z Stat.extrema..Ys-GGGqtvabbz""GGGrrr)rr r r!rrr)rr(s`@rextremaz Stat.extrema>sL $ $ $ $HGGGGE!S[[#,F,FGGGGrr cbfdtdtjdDS)z2Total number of pixels for each band in the image.cNg|]!}tj||dz"S)r)sumrr+r'rs rr,zStat.count..^s0MMMQDF1q3w;'((MMMrrrr-rs`rcountz Stat.count[s4NMMM%3tv;;2L2LMMMMr list[float]cg}tdt|jdD]A}d}tdD]}|||j||zzz }||B|S)z-Sum of all pixels for each band in the image.rr)rrrappend)rvr' layer_sumjs rr1zStat.sum`s{ q#df++s++  AI3ZZ / /QA.. HHY    rc g}tdt|jdD]Q}d}tdD](}||dzt|j||zzz })||R|S)z5Squared sum of all pixels for each band in the image.rrr7)rrrfloatr8)rr9r'sum2r;s rr?z Stat.sum2ls q#df++s++  AD3ZZ 6 6Atva!e}!5!555 HHTNNNNrc*fdjDS)zAAverage (arithmetic mean) pixel level for each band in the image.cdg|],}j|rj|j|z nd-Sr)r4r1r2s rr,zStat.mean..{s:XXXtz!}C djm++!XXXrrr3s`rmeanz Stat.meanxs"YXXXTZXXXXrcg}|jD][}d}|j|dz}|dz}tdD]}||j||zz}||krn||\|S)z.Median pixel level for each band in the image.rr=r)rr4rrr8)rr9r'shalfbr;s rmedianz Stat.median}s   AA:a=A%DCA3ZZ  q1u %t88E HHQKKKKrc*fdjDS)z2RMS (root-mean-square) for each band in the image.cg|]>}j|r-tjj|j|z nd?SrB)r4mathsqrtr?r2s rr,zStat.rms..sT   8.sk   :a=1!!3tz!} DD ST UU    rrCr3s`rvarzStat.vars2    Z     rc*fdjDS)z.Standard deviation for each band in the image.cNg|]!}tjj|"S)rLrMrQr2s rr,zStat.stddev..s);;;1 $(1+&&;;;rrCr3s`rstddevz Stat.stddevs!<;;; ;;;;rr*)r r r r r r)r r)r r )r r5)__name__ __module__ __qualname__rrr.r4r1r?rDrIrNrQrUrTrrrrs\QU55555<HHH_H8NNN_N   _    _ YYY_Y   _    _     _  <<<_<<r]s.#""""" %%%%%%E<E<E<E<E<E<E<E