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
Ë
³òúh{"ãód—ddlmZddlZddlmZmZdZgd¢Zgd¢ZGd„d    «Z    Gd
„d «Z
y) é)Ú annotationsNé)ÚImageÚ _imagingmorphi)    ééréérééé)    r rrr r
rr r    rcóf—eZdZdZ    d
                    d d„Zd d„Zd d„Zdd„Zdd„Z                                dd„Z    dd    „Z
y)Ú
LutBuilderaTA 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óž—|||_ng|_d|_|3ddgdgddgdgddggd¢dœ}||vrd    |›d
}t|«‚|||_yy) Nú1:(... ... ...)->0z4:(00. 01. ...)->1z4:(... .0. .1.)->1z4:(... .0. ..1)->1z4:(... .1. .0.)->0z4:(... .1. ..0)->0)rz4:(.0. .1. ...)->1z4:(01. .1. ...)->1)ÚcornerÚ    dilation4Ú    dilation8Úerosion4Úerosion8ÚedgezUnknown pattern ú!)ÚpatternsÚlutÚ    Exception)ÚselfrÚop_nameÚknown_patternsÚmsgs     úAH:\Change_password\venv_build\Lib\site-packages\PIL/ImageMorph.pyÚ__init__zLutBuilder.__init__As‹€ð Ð Ø$ˆDMàˆDŒMØ%)ˆŒØ Ð à/Ð1EÐFØ2Ð3Ø2Ð4HÐIØ1Ð2Ø1Ð3GÐHòñ ˆNð˜nÑ,Ø(¨¨    °Ð3Ü “nÐ$à*¨7Ñ3ˆDMð# ócó.—|xj|z c_y©N©r)rrs  r Ú add_patternszLutBuilder.add_patterns\s€Ø  Š ˜Ñ!Ž r"cób‡‡—ddgŠdŠtˆˆfd„tt«D««|_y)Nrréc3ó4•K—|]}‰|‰zdkD–—Œy­w)rN©)Ú.0ÚiÚmÚsymbolss  €€r ú    <genexpr>z/LutBuilder.build_default_lut.<locals>.<genexpr>bsøèø€ÒK°a˜W a¨!¡e¨q¡[Õ1ÑKùsƒ)Ú    bytearrayÚrangeÚLUT_SIZEr)rr-r.s @@r Úbuild_default_lutzLutBuilder.build_default_lut_s'ù€Øa&ˆØ ˆÜÔK¼5Ä»?ÔKÓKˆr"có—|jSr$©r)rs r Úget_lutzLutBuilder.get_lutds €Øx‰xˆr"cóX‡—t|«dk(sJ‚djˆfd„|D««S)z„string_permute takes a pattern and a permutation and returns the
        string permuted according to the permutation list.
        é    Úc3ó(•K—|]    }‰|–—Œ y­wr$r*)r+ÚpÚpatterns  €r r/z-LutBuilder._string_permute.<locals>.<genexpr>lsøèø€Ò7 aw˜q•zÑ7ùsƒ)ÚlenÚjoin)rr<Ú permutations ` r Ú_string_permutezLutBuilder._string_permutegs-ø€ô;Ó 1Ò$Ð$Ð$؏w‰wÓ7¨;Ô7Ó7Ð7r"có—||fg}d|vrE|dd}td«D]/}|j|j|ddt«|f«Œ1d|vr?t    |«}|d|D],\}}|j|j|t
«|f«Œ.d|vrkt    |«}|d|D]X\}}|j d    d
«j d d    «j d
d «}dt|«z
}|j||f«ŒZ|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éÿÿÿÿrr
rÚMNÚNÚ0ÚZÚ1)r1Úappendr@ÚROTATION_MATRIXr=Ú MIRROR_MATRIXÚreplaceÚint)    rÚ basic_patternÚoptionsÚ basic_resultrÚresr,Únr<s             r Ú_pattern_permutezLutBuilder._pattern_permutens(€ð # LÐ1Ð2ˆð '‰>ؘ2‘,˜q‘/ˆCܘ1“Xò Ø—‘Ø×)Ñ)¨(°2©,°q©/¼?ÓKÈSÐQõð ð
'‰>ܐH“ ˆAØ (¨¨!  ò U‘ ˜Ø—‘ ×!5Ñ!5°g¼}Ó!MÈsРSÕTð Uð '‰>ܐH“ ˆAØ (¨¨!  ò 0‘ ˜à!Ÿ/™/¨#¨sÓ3×;Ñ;¸CÀÓE×MÑMÈcÐSVÓWØœ#˜c›(‘lØ—‘ ¨# Õ/ð     0ð ˆr"có`—|j«|j€J‚g}|jD]±}tjd|j dd««}|sd|zdz}t |«‚|jd«}|jd«}t|jd    ««}|j d
d«j dd«}||j|||«z }Œ³g}|D]P}|d j d d «j d d«}|jtj|«|df«ŒRtt«D]Z}    t|    «dd}
ddt|
«z
z|
zddd…}
|D]+\}} |j!|
«sŒd dg| |j|    <Œ-Œ\|jS)zlCompile all patterns into a morphology lut.
 
        TBD :Build based on (file) morphlut:modify_lut
        Nz(\w):?\s*\((.+?)\)\s*->\s*(\d)ú
r9zSyntax error in pattern "ú"rr rú rú.ÚXz[01]rFr8rC)r3rrÚreÚsearchrLrÚgrouprMrSrIÚcompiler1r2Úbinr=Úmatch) rrr;r-rrOr<ÚresultÚcompiled_patternsr,Ú
bitpatternÚrs             r Ú    build_lutzLutBuilder.build_lutŽs¶€ð
     ×ÑԠ؏x‰xÐ#Ð#Ð#؈ð—‘ò     HˆAÜ—    ‘    Ð;¸Q¿Y¹YÀtÈRÓ=PÓQˆAÙØ1°AÑ5¸Ñ;Ü “nÐ$Ø—g‘g˜a“jˆGØ—g‘g˜a“jˆGܘŸ™ ›“_ˆFð—o‘o c¨2Ó.×6Ñ6°t¸RÓ@ˆGà ˜×-Ñ-¨g°wÀÓGÑ G‰Hð     HðÐØò    BˆGؘ‘
×"Ñ" 3¨Ó,×4Ñ4°S¸&ÓAˆAØ × $Ñ $¤b§j¡j°£m°W¸Q±ZÐ%@Õ Að    Bô”x“ò    ,ˆAä˜Q›  ˜ˆJØ ¤S¨£_Ñ!4Ñ5¸
ÑBÁDÀbÀDÑIˆJà/ò ,‘
˜Ø—=‘= Õ,Ø#$ a &¨¡)D—H‘H˜Q’Kñ ,ð     ,ðx‰xˆr")NN)rúlist[str] | Nonerú
str | NoneÚreturnÚNone)rz    list[str]rgrh)rgrh)rgúbytearray | None)r<Ústrr?z    list[int]rgrj)rNrjrOrjrPrMrgzlist[tuple[str, int]])rgr0) Ú__name__Ú
__module__Ú __qualname__Ú__doc__r!r&r3r6r@rSrdr*r"r rrsl„ñ!ðHHLð4Ø(ð4Ø:Dð4à     ó4ó6"óLó
ó8ðØ ðØ+.ðØ>Aðà    óô@*r"rcó^—eZdZdZ            d
                            d d„Zd d„Zd d„Zd d„Zdd„Zdd„Z    dd    „Z
y)ÚMorphOpz*A class for binary morphological operatorsNcóš—||_| t|¬«j«|_y| t|¬«j«|_yy)z&Create a binary morphological operatorN)rr%)rrrd)rrrrs    r r!zMorphOp.__init__¾sF€ðˆŒØ Ð Ü!¨'Ô2×<Ñ<Ó>ˆDHØ Ð !Ü!¨8Ô4×>Ñ>Ó@ˆDHð"r"cóV—|j€ d}t|«‚|jdk7r d}t|«‚t    j
|j|j d«}tjt|j«|j«|j««}||fS)z‡Run a single morphological operation on an image
 
        Returns a tuple of the number of changed pixels and the
        morphed imageNúNo operator loadedÚLúImage mode must be L) rrÚmodeÚ
ValueErrorrÚnewÚsizerÚapplyÚbytesÚgetim)rÚimagerÚoutimageÚcounts     r rzz MorphOp.applyËs…€ð
8‰8Ð Ø&ˆCܘC“.Ð  à :‰:˜Ò Ø(ˆCܘS“/Ð !Ü—9‘9˜UŸZ™Z¨¯©°TÓ:ˆÜ×#Ñ#¤E¨$¯(©(£O°U·[±[³]ÀHÇNÁNÓDTÓUˆØhˆÐr"cóڗ|j€ d}t|«‚|jdk7r d}t|«‚t    j
t |j«|j««S)zÈGet a list of coordinates matching the morphological operation on
        an image.
 
        Returns a list of tuples of (x,y) coordinates
        of all matching pixels. See :ref:`coordinate-system`.rsrtru)rrrvrwrr_r{r|©rr}rs   r r_z MorphOp.matchÛsY€ð 8‰8Ð Ø&ˆCܘC“.Ð  à :‰:˜Ò Ø(ˆCܘS“/Ð !Ü×"Ñ"¤5¨¯©£?°E·K±K³MÓBÐBr"có€—|jdk7r d}t|«‚tj|j    ««S)z©Get a list of all turned on pixels in a binary image
 
        Returns a list of tuples of (x,y) coordinates
        of all matching pixels. See :ref:`coordinate-system`.rtru)rvrwrÚ get_on_pixelsr|rs   r rƒzMorphOp.get_on_pixelsês6€ð :‰:˜Ò Ø(ˆCܘS“/Ð !Ü×*Ñ*¨5¯;©;«=Ó9Ð9r"cóâ—t|d«5}t|j««|_ddd«t    |j«t
k7rd|_d}t |«‚y#1swYŒ:xYw)z!Load an operator from an mrl fileÚrbNzWrong size operator file!)Úopenr0Úreadrr=r2r)rÚfilenameÚfrs    r Úload_lutzMorphOp.load_lutõsb€ä (˜DÓ !ð    + QÜ  §¡£Ó*ˆDŒH÷    +ô ˆtx‰x‹=œHÒ $؈DŒHØ-ˆCܘC“.Ð  ð %÷    +ð    +ús A%Á%A.có®—|j€ d}t|«‚t|d«5}|j|j«ddd«y#1swYyxYw)zSave an operator to an mrl fileNrsÚwb)rrr†Úwrite)rrˆrr‰s    r Úsave_lutzMorphOp.save_lutÿsL€à 8‰8Ð Ø&ˆCܘC“.Ð  Ü (˜DÓ !ð     QØ G‰GD—H‘HÔ ÷    ÷    ñ    ús ¦A Á Acó—||_y)z#Set the lut from an external sourceNr5)rrs  r Úset_lutzMorphOp.set_luts    €àˆr")NNN)rrirrfrrergrh)r}ú Image.Imagergztuple[int, Image.Image])r}r‘rgzlist[tuple[int, int]])rˆrjrgrh)rrirgrh) rkrlrmrnr!rzr_rƒrŠrŽrr*r"r rprp»s_„Ù4ð!%Ø"Ø%)ð     Aà ð Aðð Að#ð     Að
 
ó Aóó  Có    :ó!óôr"rp) Ú
__future__rrZr9rrr2rJrKrrpr*r"r ú<module>r“s<ðõ#ã    ç"à €ò€ò
€ ÷[ñ[÷|NòNr"