1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
U
T±d{Bã@szddlZGdd„dƒZGdd„deƒZGdd„deƒZGdd    „d    eƒZGd
d „d eƒZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deƒZ    Gdd„deƒZ
Gdd„deƒZ Gdd„deƒZ Gdd„deƒZ Gdd„deƒZGdd„deƒZGd d!„d!eƒZGd"d#„d#eƒZGd$d%„d%eƒZGd&d'„d'eƒZGd(d)„d)eƒZGd*d+„d+eƒZGd,d-„d-eƒZGd.d/„d/eƒZdS)0éNc@s eZdZdS)ÚFilterN©Ú__name__Ú
__module__Ú __qualname__©rrúFd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PIL/ImageFilter.pyrsrc@s eZdZdS)ÚMultibandFilterNrrrrrr    sr    c@seZdZdd„ZdS)Ú BuiltinFiltercCs"|jdkrd}t|ƒ‚|j|jŽS)NÚPúcannot filter palette images)ÚmodeÚ
ValueErrorÚfilterÚ
filterargs©ÚselfÚimageÚmsgrrrrs
zBuiltinFilter.filterN)rrrrrrrrr
sr
c@seZdZdZdZddd„ZdS)ÚKernelaÎ
    Create a convolution kernel.  The current version only
    supports 3x3 and 5x5 integer and floating point kernels.
 
    In the current version, kernels can only be applied to
    "L" and "RGB" images.
 
    :param size: Kernel size, given as (width, height). In the current
                    version, this must be (3,3) or (5,5).
    :param kernel: A sequence containing kernel weights.
    :param scale: Scale factor. If given, the result for each pixel is
                    divided by this value.  The default is the sum of the
                    kernel weights.
    :param offset: Offset. If given, this value is added to the result,
                    after it has been divided by the scale factor.
    NrcCsN|dkrt dd„|¡}|d|dt|ƒkr<d}t|ƒ‚||||f|_dS)NcSs||S©Nr)ÚaÚbrrrÚ<lambda>;óz!Kernel.__init__.<locals>.<lambda>réz!not enough coefficients in kernel)Ú    functoolsÚreduceÚlenrr)rÚsizeÚkernelZscaleÚoffsetrrrrÚ__init__8s zKernel.__init__)Nr©rrrÚ__doc__Únamer"rrrrr$src@s$eZdZdZdZdd„Zdd„ZdS)Ú
RankFilterao
    Create a rank filter.  The rank filter sorts all pixels in
    a window of the given size, and returns the ``rank``'th value.
 
    :param size: The kernel size, in pixels.
    :param rank: What pixel value to pick.  Use 0 for a min filter,
                 ``size * size / 2`` for a median filter, ``size * size - 1``
                 for a max filter, etc.
    ZRankcCs||_||_dSr©rÚrank)rrr(rrrr"OszRankFilter.__init__cCs>|jdkrd}t|ƒ‚| |jd|jd¡}| |j|j¡S)Nr r é)r rÚexpandrZ
rankfilterr(rrrrrSs
 
zRankFilter.filterN©rrrr$r%r"rrrrrr&Bs
r&c@seZdZdZdZddd„ZdS)Ú MedianFilterz‘
    Create a median filter. Picks the median pixel value in a window with the
    given size.
 
    :param size: The kernel size, in pixels.
    ZMedianécCs||_||d|_dS)Nr)r'©rrrrrr"eszMedianFilter.__init__N)r-r#rrrrr,[sr,c@seZdZdZdZddd„ZdS)Ú    MinFilterz
    Create a min filter.  Picks the lowest pixel value in a window with the
    given size.
 
    :param size: The kernel size, in pixels.
    ZMinr-cCs||_d|_dS)Nrr'r.rrrr"tszMinFilter.__init__N)r-r#rrrrr/jsr/c@seZdZdZdZddd„ZdS)Ú    MaxFilterz
    Create a max filter.  Picks the largest pixel value in a window with the
    given size.
 
    :param size: The kernel size, in pixels.
    ZMaxr-cCs||_||d|_dS)Nrr'r.rrrr"ƒszMaxFilter.__init__N)r-r#rrrrr0ysr0c@s&eZdZdZdZd    dd„Zdd„ZdS)
Ú
ModeFiltera!
    Create a mode filter. Picks the most frequent pixel value in a box with the
    given size.  Pixel values that occur only once or twice are ignored; if no
    pixel value occurs more than twice, the original pixel value is preserved.
 
    :param size: The kernel size, in pixels.
    ZModer-cCs
||_dSr)rr.rrrr"“szModeFilter.__init__cCs | |j¡Sr)Z
modefilterr©rrrrrr–szModeFilter.filterN)r-r+rrrrr1ˆs
r1c@s&eZdZdZdZddd„Zdd„ZdS)    Ú GaussianBluraBlurs the image with a sequence of extended box filters, which
    approximates a Gaussian kernel. For details on accuracy see
    <https://www.mia.uni-saarland.de/Publications/gwosdek-ssvm11.pdf>
 
    :param radius: Standard deviation of the Gaussian kernel.
    r)cCs
||_dSr)Úradius)rr4rrrr"¤szGaussianBlur.__init__cCs | |j¡Sr)Z gaussian_blurr4r2rrrr§szGaussianBlur.filterN)r)r+rrrrr3šs
r3c@s$eZdZdZdZdd„Zdd„ZdS)ÚBoxBluraBlurs the image by setting each pixel to the average value of the pixels
    in a square box extending radius pixels in each direction.
    Supports float radius of arbitrary size. Uses an optimized implementation
    which runs in linear time relative to the size of the image
    for any radius value.
 
    :param radius: Size of the box in one direction. Radius 0 does not blur,
                   returns an identical image. Radius 1 takes 1 pixel
                   in each direction, i.e. 9 pixels in total.
    cCs|dkrd}t|ƒ‚||_dS)Nrzradius must be >= 0)rr4)rr4rrrrr"¹szBoxBlur.__init__cCs | |j¡Sr)Zbox_blurr4r2rrrr¿szBoxBlur.filterNr+rrrrr5«s r5c@s&eZdZdZdZd
dd„Zdd„Zd    S) Ú UnsharpMaskašUnsharp mask filter.
 
    See Wikipedia's entry on `digital unsharp masking`_ for an explanation of
    the parameters.
 
    :param radius: Blur Radius
    :param percent: Unsharp strength, in percent
    :param threshold: Threshold controls the minimum brightness change that
      will be sharpened
 
    .. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking
 
    r)é–r-cCs||_||_||_dSr)r4ÚpercentÚ    threshold)rr4r8r9rrrr"ÔszUnsharpMask.__init__cCs| |j|j|j¡Sr)Z unsharp_maskr4r8r9r2rrrrÙszUnsharpMask.filterN)r)r7r-r+rrrrr6Ãs
r6c@seZdZdZdZdS)ÚBLURZBlur)©ér<ér)rrrrrrrrrrrrrrrrrrrrrrrrrN©rrrr%rrrrrr:Ýsr:c@seZdZdZdZdS)ÚCONTOURZContour)©r-r-réÿ©    éÿÿÿÿrCrCrCérCrCrCrCNr>rrrrr?êsr?c@seZdZdZdZdS)ÚDETAILZDetail)r@ér)    rrCrrCé
rCrrCrNr>rrrrrEõsrEc@seZdZdZdZdS)Ú EDGE_ENHANCEz Edge-enhance)r@r)r)    rCrCrCrCrGrCrCrCrCNr>rrrrrHsrHc@seZdZdZdZdS)ÚEDGE_ENHANCE_MOREzEdge-enhance More)r@rr)    rCrCrCrCé    rCrCrCrCNr>rrrrrI srIc@seZdZdZdZdS)ÚEMBOSSZEmboss)r@ré€)    rCrrrrrrrrNr>rrrrrKsrKc@seZdZdZdZdS)Ú
FIND_EDGESz
Find Edges)r@rrrBNr>rrrrrM!srMc@seZdZdZdZdS)ÚSHARPENZSharpen)r@r=r)    éþÿÿÿrOrOrOé rOrOrOrONr>rrrrrN,srNc@seZdZdZdZdS)ÚSMOOTHZSmooth)r@é r)    rrrrr<rrrrNr>rrrrrQ7srQc@seZdZdZdZdS)Ú SMOOTH_MOREz Smooth More)r;édr)rrrrrrr<r<r<rrr<é,r<rrr<r<r<rrrrrrNr>rrrrrSBsrSc@sReZdZdZdZddd„Zedd„ƒZedd    d
„ƒZ    dd d „Z
dd„Z dd„Z dS)Ú
Color3DLUTaŒThree-dimensional color lookup table.
 
    Transforms 3-channel pixels using the values of the channels as coordinates
    in the 3D lookup table and interpolating the nearest elements.
 
    This method allows you to apply almost any color transformation
    in constant time by using pre-calculated decimated tables.
 
    .. versionadded:: 5.2.0
 
    :param size: Size of the table. One int or tuple of (int, int, int).
                 Minimal size in any dimension is 2, maximum is 65.
    :param table: Flat lookup table. A list of ``channels * size**3``
                  float elements or a list of ``size**3`` channels-sized
                  tuples with floats. Channels are changed first,
                  then first dimension, then second, then third.
                  Value 0.0 corresponds lowest value of output, 1.0 highest.
    :param channels: Number of channels in the table. Could be 3 or 4.
                     Default is 3.
    :param target_mode: A mode for the result image. Should have not less
                        than ``channels`` channels. Default is ``None``,
                        which means that mode wouldn't be changed.
    z Color 3D LUTr-Nc Ks¬|dkrd}t|ƒ‚| |¡|_}||_||_| dd¡}|d|d|d}d}    d}
t|d    ƒrˆz ddl}
Wntk
r†YnX|
rèt    ||
j
ƒrè|r¤|  ¡}|j ||f||f|d|d|d|ffkrâ|  ||¡}nd}    nh|rôt|ƒ}|rPt    |dttfƒrPg|}} | D]2} t| ƒ|krBd
|›d }t|ƒ‚| | ¡q|    sht|ƒ||kr¢d |›d |d›d |d›d |d›dt|ƒ›
}t|ƒ‚||_dS)N©r-éú)Only 3 or 4 output channels are supportedÚ _copy_tableTrrr)FÚshapez2The elements of the table should have a length of Ú.z„The table should have either channels * size**3 float items or size**3 items of channels-sized tuples with floats. Table should be: Úxz. Actual length: )rÚ _check_sizerÚchannelsr ÚgetÚhasattrÚnumpyÚ ImportErrorÚ
isinstanceZndarrayÚcopyr[ZreshapeÚlistÚtuplerÚextendÚtable) rrrir_Ú target_modeÚkwargsrZ
copy_tableÚitemsZ
wrong_sizerbZ    raw_tableZpixelrrrr"jsP 
 ý
 
ÿ0ÿzColor3DLUT.__init__c
Csšz|\}}}WnLtk
r>}zd}t|ƒ|‚W5d}~XYntk
rZ|||f}YnXdd„|Dƒ}|D]&}d|kr†dksnnd}t|ƒ‚qn|S)Nz>Size should be either an integer or a tuple of three integers.cSsg|] }t|ƒ‘qSr)Úint)Ú.0r]rrrÚ
<listcomp>¯sz*Color3DLUT._check_size.<locals>.<listcomp>r)éAz Size should be in [2, 65] range.)rÚ    TypeError)rÚ_ÚerÚsize_1drrrr^¦s
zColor3DLUT._check_sizec    Cs¸| |¡\}}}|dkr$d}t|ƒ‚dg||||}    d}
t|ƒD]X} t|ƒD]J} t|ƒD]<} || |d| |d| |dƒ|    |
|
|…<|
|7}
q^qRqF||||f|    ||ddS)aSGenerates new LUT using provided callback.
 
        :param size: Size of the table. Passed to the constructor.
        :param callback: Function with three parameters which correspond
                         three color channels. Will be called ``size**3``
                         times with values from 0.0 to 1.0 and should return
                         a tuple with ``channels`` elements.
        :param channels: The number of channels which should return callback.
        :param target_mode: Passed to the constructor of the resulting
                            lookup table.
        rWrYrrF©r_rjrZ)r^rÚrange)ÚclsrÚcallbackr_rjrtÚsize_2dÚsize_3drriÚidx_outrÚgÚrrrrÚgenerate¶s,    
 
 
ÿûzColor3DLUT.generateFc    Csþ|dkrd}t|ƒ‚|j}|p |}|j\}}    }
dg||    |
|} d} d} t|
ƒD]Š}t|    ƒD]|}t|ƒD]n}|j| | |…}|r²|||d||    d||
df|žŽ}n||Ž}|| | | |…<| |7} | |7} qlq`qTt|ƒ|j| ||pö|jddS)a#Transforms the table values using provided callback and returns
        a new LUT with altered values.
 
        :param callback: A function which takes old lookup table values
                         and returns a new set of values. The number
                         of arguments which function should take is
                         ``self.channels`` or ``3 + self.channels``
                         if ``with_normals`` flag is set.
                         Should return a tuple of ``self.channels`` or
                         ``channels`` elements if it is set.
        :param with_normals: If true, ``callback`` will be called with
                             coordinates in the color cube as the first
                             three arguments. Otherwise, ``callback``
                             will be called only with actual color values.
        :param channels: The number of channels in the resulting lookup table.
        :param target_mode: Passed to the constructor of the resulting
                            lookup table.
        )Nr-rXrYrrFru)rr_rrvriÚtyper )rrxZ with_normalsr_rjrZch_inZch_outrtryrzriZidx_inr{rr|r}ÚvaluesrrrÚ    transformÚs@    
 
 
ýüûzColor3DLUT.transformcCsX|jj›d|jjj›dj|jŽd|jd›g}|jrH| d|j›¡d d |¡¡S)Nz from zsize={:d}x{:d}x{:d}z    channels=Údz target_mode=z<{}>ú )    Ú    __class__rriÚformatrr_r ÚappendÚjoin)rr}rrrÚ__repr__s
 ýzColor3DLUT.__repr__c    CsDddlm}| |jp|j|jj|j|jd|jd|jd|j¡S)Nr)ÚImagerr))    Úr‰Z color_lut_3dr Z
ResamplingZBILINEARr_rri)rrr‰rrrrs 
ùzColor3DLUT.filter)r-N)r-N)FNN) rrrr$r%r"Ú staticmethodr^Ú classmethodr~rrˆrrrrrrVOs
<
 #
6
rV)rrr    r
rr&r,r/r0r1r3r5r6r:r?rErHrIrKrMrNrQrSrVrrrrÚ<module>s.