CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
ImageOps.cpython-310.pyc325 linesDownload Raw Back to __pycache__
1o

2��Yi�f�@s�ddlmZddlZddlZddlZddlmZddlmZm	Z	m3Z4mZddlm
Z
mZmZdjdd�Zdkdd�Zdldd�Z				dmdnd"d#�Z			$	%dodpd/d0�Zejjfdqd4d5�Zejjfdqd6d7�Zejjdd8fdrd;d<�Zdsdtd=d>�ZejjfdudBdC�ZGdDdE�dEe	�ZejjfdvdGdH�ZdwdxdIdJ�Z		dydzdLdM�Z ejjdNd8fd{dPdQ�Z!d|dRdS�Z"d|dTdU�Z#d|dVdW�Z$d|dXdY�Z%d}d[d\�Z&d~dd_d`�Z'ed�ddde��Z(eddf�d�dhde��Z(ddf�d�dide�Z(dS)��)�annotationsN)�Sequence)�Literal�Protocol�cast�overload�)�ExifTags�Image�ImagePalette�border�int | tuple[int, ...]�return�tuple[int, int, int, int]cCs^t|t�r!t|�dkr|\}}\}}nt|�dkr |\}}}}n|}}}}||||fS)N��)�5isinstance�tuple�len)r�left�top�right�bottom�r�vE:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\PIL/ImageOps.py�_border!s6�r�color�str | int | tuple[int, ...]�mode�strcCs&t|t�rddlm}|�||�}|S)Nr)�7ImageColor)rr�r �getcolor)rrr rrr�_color,s8r#�image�Image.Image�lut�	list[int]cCs`|jdkrd}t|��|jdvr&|jdkr!t|�dkr!|||}|�|�Sd|j��}t|��)N�Pzmode P support coming soon)�L�RGBr*�znot supported for mode )r�NotImplementedErrorr�point�OSError)r$r&�msgrrr�_lut4s91011r0F�cutoff�float | tuple[float, float]�ignore�int | Sequence[int] | None�mask�Image.Image | None�
preserve_tone�boolcCs2|r|�d��|�}n|�|�}g}tdt|�d�D]�}|||d�}|dur;t|t�r2d||<n	|D]}	d||	<q4|r�t|t�sF||f}d}12td�D]}	|13||	}14qLt|15|dd�}td�D]#}|||krv|||}d||<n16|||8<d}|dkr�nqct|17|dd�}tddd�D]#}
|||
kr�|||
}d||
<n18||
|8<d}|dkr�nq�td�D]}||r�nq�tddd�D]}
||
r�nq�|
|kr�|�ttd���qd	|
|}||}td�D]}	t|	||�}	|	dk�rd}	n|	dk�r
d}	|�	|	�q�qt19||�S)20a�21    Maximize (normalize) image contrast. This function calculates a22    histogram of the input image (or mask region), removes ``cutoff`` percent of the23    lightest and darkest pixels from the histogram, and remaps the image24    so that the darkest pixel becomes black (0), and the lightest25    becomes white (255).26 27    :param image: The image to process.28    :param cutoff: The percent to cut off from the histogram on the low and29                   high ends. Either a tuple of (low, high), or a single30                   number for both.31    :param ignore: The background pixel value (use None for no background).32    :param mask: Histogram used in contrast operation is computed using pixels33                 within the mask. If no mask is given the entire image is used34                 for histogram computation.35    :param preserve_tone: Preserve image tone in Photoshop-like style autocontrast.36 37                          .. versionadded:: 8.2.038 39    :return: An image.40    r)rr+N�dr�������g�o@)�convert�	histogram�rangerr�intr�extend�list�appendr0)r$r1r3r5r7r=r&�layer�hZix�n�cut�lo�hi�scale�offsetrrr�autocontrastFst414243444546�47���484950�51rKr:��black�str | tuple[int, ...]�white�mid�"str | int | tuple[int, ...] | None�52blackpointr?�53whitepoint�midpointcCs|jdksJ�|durd|kr|krdksJ�J�nd|kr4|kr4|kr4dks7J�J�tttt|d��}tttt|d��}|durYtttt|d��nd}	g}54g}g}t|�D]}
|55�|d�|�|d�|�|d�qe|	dur�t||�}|D]A}
|56�|d|
|d|dt|��|�|d|
|d|dt|��|�|d|
|d|dt|��q�n�t||�}t||�}|D]A}
|57�|d|
|	d|dt|��|�|d|
|	d|dt|��|�|d|
|	d|dt|��q�|D]B}
|58�|	d|
|d|	dt|��|�|	d|
|d|	dt|��|�|	d|
|d|	dt|���qtd|�D]}
|59�|d�|�|d�|�|d��qg|�d�}t	||60||�S)	a�61    Colorize grayscale image.62    This function calculates a color wedge which maps all black pixels in63    the source image to the first color and all white pixels to the64    second color. If ``mid`` is specified, it uses three-color mapping.65    The ``black`` and ``white`` arguments should be RGB tuples or color names;66    optionally you can use three-color mapping by also specifying ``mid``.67    Mapping positions for any of the colors can be specified68    (e.g. ``blackpoint``), where these parameters are the integer69    value corresponding to where the corresponding color should be mapped.70    These parameters must have logical order, such that71    ``blackpoint <= midpoint <= whitepoint`` (if ``mid`` is specified).72 73    :param image: The image to colorize.74    :param black: The color to use for black input pixels.75    :param white: The color to use for white input pixels.76    :param mid: The color to use for midtone input pixels.77    :param blackpoint: an int value [0, 255] for the black mapping.78    :param whitepoint: an int value [0, 255] for the white mapping.79    :param midpoint: an int value [0, 255] for the midtone mapping.80    :return: An image.81    r)Nrr:r*rrr+)82rrrr?r#r>rBrr<r0)r$rMrOrPrRrSrTZ	rgb_blackZ	rgb_whiteZrgb_mid�red�green�blue�iZ	range_mapZ83range_map1Z84range_map2rrr�colorize�sf!(0 "�"�"��
"�"�"�*"�.85rY�size�tuple[int, int]�methodcCs�|j|j}|d|d}||krG||kr/t|j|j|d�}||dkr.|d|f}nt|j|j|d�}||dkrG||df}|j||d�S)a�86    Returns a resized version of the image, set to the maximum width and height87    within the requested size, while maintaining the original aspect ratio.88 89    :param image: The image to resize.90    :param size: The requested output size in pixels, given as a91                 (width, height) tuple.92    :param method: Resampling method to use. Default is93                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.94                   See :ref:`concept-filters`.95    :return: An image.96    rr��resample��width�height�round�resize�r$rZr\Zim_ratioZ97dest_ratioZ98new_heightZ	new_widthrrr�contain
��recCs�|j|j}|d|d}||krG||kr/t|j|j|d�}||dkr.|d|f}nt|j|j|d�}||dkrG||df}|j||d�S)a�99    Returns a resized version of the image, so that the requested size is100    covered, while maintaining the original aspect ratio.101 102    :param image: The image to resize.103    :param size: The requested output size in pixels, given as a104                 (width, height) tuple.105    :param method: Resampling method to use. Default is106                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.107                   See :ref:`concept-filters`.108    :return: An image.109    rrr]r_rdrrr�cover,rfrg)��?rh�	centering�tuple[float, float]c110Cs�t|||�}|j|kr|}|St�|j||�}|jr'|��}|dur'|�|�|j|dkrKt	|d|jt111dt|dd���}|�||df�|St	|d|j
t112dt|dd���}	|�|d|	f�|S)at113    Returns a resized and padded version of the image, expanded to fill the114    requested aspect ratio and size.115 116    :param image: The image to resize and crop.117    :param size: The requested output size in pixels, given as a118                 (width, height) tuple.119    :param method: Resampling method to use. Default is120                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.121                   See :ref:`concept-filters`.122    :param color: The background color of the padded image.123    :param centering: Control the position of the original image within the124                      padded version.125 126                          (0.5, 0.5) will keep the image centered127                          (0, 0) will keep the image aligned to the top left128                          (1, 1) will keep the image aligned to the bottom129                          right130    :return: An image.131    Nrr)rerZr132�newr�palette�133getpalette�134putpaletter`rb�max�min�pastera)135r$rZr\rriZresized�outrl�x�yrrr�padKs 136
�137&&�rucCs6t|�\}}}}|�|||jd||jd|f�S)a/138    Remove border from image.  The same amount of pixels are removed139    from all four sides.  This function works on all image modes.140 141    .. seealso:: :py:meth:`~PIL.Image.Image.crop`142 143    :param image: The image to crop.144    :param border: The number of pixels to remove.145    :return: An image.146    rr)r�croprZ)r$rrrrrrrrrvys&rv�factor�floatr^cCsL|dkr|��S|dkrd}t|��t||j�t||j�f}|�||�S)a�147    Returns a rescaled image by a specific factor given in parameter.148    A factor greater than 1 expands the image, between 0 and 1 contracts the149    image.150 151    :param image: The image to rescale.152    :param factor: The expansion factor, as a float.153    :param resample: Resampling method to use. Default is154                     :py:attr:`~PIL.Image.Resampling.BICUBIC`.155                     See :ref:`concept-filters`.156    :returns: An :py:class:`~PIL.Image.Image` object.157    rrz!the factor must be greater than 0)�copy�158ValueErrorrbr`rarc)r$rwr^r/rZrrrrI�srIc@seZdZdZd	dd�ZdS)159�SupportsGetMeshaE160    An object that supports the ``getmesh`` method, taking an image as an161    argument, and returning a list of tuples. Each tuple contains two tuples,162    the source box as a tuple of 4 integers, and a tuple of 8 integers for the163    final quadrilateral, in order of top left, bottom left, bottom right, top164    right.165    r$r%r�Ulist[tuple[tuple[int, int, int, int], tuple[int, int, int, int, int, int, int, int]]]cC�dS�Nr)�selfr$rrr�getmesh�szSupportsGetMesh.getmeshN)r$r%rr|)�__name__�166__module__�__qualname__�__doc__r�rrrrr{�sr{�deformercCs|�|jtjj|�|�|�S)aL167    Deform the image.168 169    :param image: The image to deform.170    :param deformer: A deformer object.  Any object that implements a171                    ``getmesh`` method can be used.172    :param resample: An optional resampling filter. Same values possible as173       in the PIL.Image.transform function.174    :return: An image.175    )�	transformrZr176Z	TransformZMESHr�)r$r�r^rrr�deform�s�r�c	Cs�|jdkr177|�d�}|�|�}g}tdt|�d�D]R}dd�|||d�D�}t|�dkr8|�ttd���qt�t	j178|�|dd	}|sQ|�ttd���q|d179}td�D]}|�||�||||}qYqt||�S)a�180    Equalize the image histogram. This function applies a non-linear181    mapping to the input image, in order to create a uniform182    distribution of grayscale values in the output image.183 184    :param image: The image to equalize.185    :param mask: An optional mask.  If given, only the pixels selected by186                 the mask are included in the analysis.187    :return: An image.188    r(r*rr+cSsg|]}|r|�qSrr)�.0�_frrr�189<listcomp>��zequalize.<locals>.<listcomp>rr;r:r)
rr<r=r>rr@rA�	functools�reduce�operator�addrBr0)	r$r5rDr&�bZhisto�steprErXrrr�equalize�s"190191192�193r��fillc
Cs�t|�\}}}}||jd|}||jd|}t||j�}	|jrG|jj}194t�|195|�|196��}t|	t�rFt	|	�dksAt	|	�dkrF|�197|	�}	nd}t�|j||f|	�}|r\|�
|j|198�|�|||f�|S)z�199    Add border to the image200 201    :param image: The image to expand.202    :param border: Border width, in pixels.203    :param fill: Pixel fill value (a color value).  Default is 0 (black).204    :return: An image.205    rr�rN)rrZr#rrlrrmrrrr"r206rkrnrq)
r$rr�rrrrr`rarrrlrrrrr�expand�s 
"207�r���bleedcCs^|\}}d|krdksnd}d|krdksnd}d|kr(dks+nd}||jd||jdf}|jd|dd|jd|ddf}|d|d}	|d|d}208|	|209krl|d}|d}n|	|210kr{|211|d}|d}n212|d}|d|213}|d|d||}
|d|d||}|
||
|||f}|j|||d�S)a214    Returns a resized and cropped version of the image, cropped to the215    requested aspect ratio and size.216 217    This function was contributed by Kevin Cazabon.218 219    :param image: The image to resize and crop.220    :param size: The requested output size in pixels, given as a221                 (width, height) tuple.222    :param method: Resampling method to use. Default is223                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.224                   See :ref:`concept-filters`.225    :param bleed: Remove a border around the outside of the image from all226                  four edges. The value is a decimal percentage (use 0.01 for227                  one percent). The default value is 0 (no border).228                  Cannot be greater than or equal to 0.5.229    :param centering: Control the cropping position.  Use (0.5, 0.5) for230                      center cropping (e.g. if cropping the width, take 50% off231                      of the left side, and therefore 50% off the right side).232                      (0.0, 0.0) will crop from the top left corner (i.e. if233                      cropping the width, take all of the crop off of the right234                      side, and if cropping the height, take all of it off the235                      bottom).  (1.0, 0.0) will crop from the bottom left236                      corner, etc. (i.e. if cropping the width, take all of the237                      crop off the left side, and if cropping the height take238                      none from the top, and therefore all off the bottom).239    :return: An image.240    r�g�?rhrrr)�box)rZrc)r$rZr\r�riZcentering_xZcentering_yZbleed_pixelsZ	live_sizeZlive_size_ratioZoutput_ratioZ241crop_widthZcrop_heightZ	crop_leftZcrop_toprvrrr�fits2(�242243r�cC�|�tjj�S)zq244    Flip the image vertically (top to bottom).245 246    :param image: The image to flip.247    :return: An image.248    )�	transposer249�	Transpose�FLIP_TOP_BOTTOM�r$rrr�flip^�r�cCs250|�d�S)zi251    Convert the image to grayscale.252 253    :param image: The image to convert.254    :return: An image.255    r))r<r�rrr�	grayscalehs256r�cCs.ttddd��}|jdkr|�|�St||�S)zc257    Invert (negate) the image.258 259    :param image: The image to invert.260    :return: An image.261    r:r;�1)rAr>rr-r0)r$r&rrr�invertrsr�cCr�)zq262    Flip image horizontally (left to right).263 264    :param image: The image to mirror.265    :return: An image.266    )r�r267r��FLIP_LEFT_RIGHTr�rrr�mirror}r�r��bitscs2dd|d��fdd�td�D�}t||�S)z�268    Reduce the number of bits for each color channel.269 270    :param image: The image to posterize.271    :param bits: The number of bits to keep for each channel (1-8).272    :return: An image.273    r�rcsg|]}|�@�qSrr)r�rX�r5rrr��r�zposterize.<locals>.<listcomp>r+)r>r0)r$r�r&rr�r�	posterize�s274r���	thresholdcCs>g}td�D]}||kr|�|�q|�d|�qt||�S)z�275    Invert all pixel values above a threshold.276 277    :param image: The image to solarize.278    :param threshold: All pixels above this grayscale level are inverted.279    :return: An image.280    r+r:)r>rBr0)r$r�r&rXrrr�solarize�s281r��in_place�
Literal[True]�NonecCr}r~r�r$r�rrr�exif_transpose�sr�)r��Literal[False]cCr}r~rr�rrrr��sc282s�|��|��}|�tjjd�}tjjtjj	tjj283tjjtjjtjj
tjjd��|�}|dur�|r>|j�|�|_|jj|_n|�|�}|rG|n|}|��}tjj|vr�|tjj=d|jvre|��|jd<nd|jvrs|����|jd<dD]=}||jvr�dD]3�|j|}	t|	t�r�t��d|	�}	nt|	t�r�t�fd	d284�|	D��}	n	t����d|	�}	|	|j|<q~qu|s�|SdS|s�|��SdS)a285    If an image has an EXIF Orientation tag, other than 1, transpose the image286    accordingly, and remove the orientation data.287 288    :param image: The image to transpose.289    :param in_place: Boolean. Keyword-only argument.290        If ``True``, the original image is modified in-place, and ``None`` is returned.291        If ``False`` (default), a new :py:class:`~PIL.Image.Image` object is returned292        with the transposition applied. If there is no transposition, a copy of the293        image will be returned.294    r)rr�r���r�N�exifzRaw profile type exif)zXML:com.adobe.xmpZxmp)ztiff:Orientation="([0-9])"z,<tiff:Orientation>([0-9])</tiff:Orientation>r!c3s"�|]}t����d|�VqdS)�N)�re�sub�encode)r��v��patternrr�	<genexpr>�s�295�z!exif_transpose.<locals>.<genexpr>r�)�loadZgetexif�getr	ZBaseZOrientationr296r�r�Z297ROTATE_180r�Z	TRANSPOSEZ298ROTATE_270Z299TRANSVERSEZ	ROTATE_90Zimr�rZ�_size�info�tobytes�hexrrr�r�rr�ry)300r$r�Z301image_exifZorientationr\Ztransposed_imageZ302exif_imager��key�valuerr�rr��sZ��	303304305306307308309310311���)rr
rr)rrrrrr
)r$r%r&r'rr%)rNNF)r$r%r1r2r3r4r5r6r7r8rr%)Nrr:rL)r$r%rMrNrOrNrPrQrRr?rSr?rTr?rr%)r$r%rZr[r\r?rr%)r$r%rZr[r\r?rrQrirjrr%)r)r$r%rr?rr%)r$r%rwrxr^r?rr%)r$r%r�r{r^r?rr%r~)r$r%r5r6rr%)rr)r$r%rr
r�rrr%)r$r%rZr[r\r?r�rxrirjrr%)r$r%rr%)r$r%r�r?rr%)r�)r$r%r�r?rr%)r$r%r�r�rr�)r$r%r�r�rr%)r$r%r�r8rr6))�312__future__rr�r�r��collections.abcr�typingrrrrr!r	r313rrr#r0rKrYZ314ResamplingZBICUBICrergrurvrIr{ZBILINEARr�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sl315316317�d�h� �"�.��!�"�318[319 320 321 322 323324 325
�
Aluode/PerceptionLabPortable · CoolFace