| Server IP : 127.0.0.1 / Your IP : 216.73.216.109 Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10 System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64 User : SERVERWEB ( 0) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/cygwin64/lib/python3.9/site-packages/PIL/__pycache__/ |
Upload File : |
a
h�a] � @ sL d dl Z ddlmZmZ dZg d�Zg d�ZG dd� d�ZG d d
� d
�ZdS )� N� )�Image�
_imagingmorphi ) � � r � � r � � � ) r r r r
r r r r r c @ sJ e Zd ZdZddd�Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
dS )�
LutBuilderaT A class for building a MorphLut from a descriptive language
The input patterns is a list of a strings sequences like these::
4:(...
.1.
111)->1
(whitespaces including linebreaks are ignored). The option 4
describes a series of symmetry operations (in this case a
4-rotation), the pattern is described by:
- . or X - Ignore
- 1 - Pixel is on
- 0 - Pixel is off
The result of the operation is described after "->" string.
The default is to return the current pixel value, which is
returned if no other match is found.
Operations:
- 4 - 4 way rotation
- N - Negate
- 1 - Dummy op for no other operation (an op must always be given)
- M - Mirroring
Example::
lb = LutBuilder(patterns = ["4:(... .1. 111)->1"])
lut = lb.build_lut()
Nc C sp |d ur|| _ ng | _ d | _|d urlddgdgddgdgddgg d�d�}||vrbtd | d
��|| | _ d S )N�1:(... ... ...)->0z4:(00. 01. ...)->1z4:(... .0. .1.)->1z4:(... .0. ..1)->1z4:(... .1. .0.)->0z4:(... .1. ..0)->0)r
z4:(.0. .1. ...)->1z4:(01. .1. ...)->1)ZcornerZ dilation4Z dilation8Zerosion4Zerosion8ZedgezUnknown pattern �!)�patterns�lut� Exception)�selfr �op_nameZknown_patterns� r �2/usr/lib/python3.9/site-packages/PIL/ImageMorph.py�__init__@ s �zLutBuilder.__init__c C s | j |7 _ d S �N�r )r r r r r �add_patternsX s zLutBuilder.add_patternsc s. ddg�d� t � �fdd�tt�D ��| _d S )Nr r � c 3 s | ]}�|� @ d k V qdS )r Nr )�.0�i��mZsymbolsr r � <genexpr>^ � z/LutBuilder.build_default_lut.<locals>.<genexpr>)� bytearray�range�LUT_SIZEr �r r r r �build_default_lut[ s zLutBuilder.build_default_lutc C s | j S r �r r$ r r r �get_lut` s zLutBuilder.get_lutc s d� � fdd�|D ��S )z�string_permute takes a pattern and a permutation and returns the
string permuted according to the permutation list.
� c 3 s | ]}� | V qd S r r )r �p��patternr r r h r z-LutBuilder._string_permute.<locals>.<genexpr>)�join)r r+ Zpermutationr r* r �_string_permutec s zLutBuilder._string_permutec C s� ||fg}d|v rJ|d d }t d�D ]"}|�| �|d d t�|f� q&d|v r�t|�}|d|� D ]\}}|�| �|t�|f� qfd|v r�t|�}|d|� D ]>\}}|�dd ��d
d��d d
�}dt|� }|�||f� q�|S )z�pattern_permute takes a basic pattern and its result and clones
the pattern according to the modifications described in the $options
parameter. It returns a list of all cloned patterns.�4���r r r �M�N�0�Z�1)r"