Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3
ia] ã @ sh d dl Z ddlmZmZ dZddd dddd d
dg Zddd d
ddd ddg ZG dd
„ d
ƒZG dd„ dƒZdS )é Né )ÚImageÚ
_imagingmorphé é é é é é é é 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 sr |d k r|| _ ng | _ d | _|d k rnddgdgddgdgddgdddgd œ}||krdtd
| d ƒ‚|| | _ d S )Nz1:(... ... ...)->0z4:(00. 01. ...)->1z4:(... .0. .1.)->1z4:(... .0. ..1)->1z4:(... .1. .0.)->0z4:(... .1. ..0)->0z4:(.0. .1. ...)->1z4:(01. .1. ...)->1)ZcornerZ dilation4Z dilation8Zerosion4Zerosion8ZedgezUnknown pattern ú!)ÚpatternsÚlutÚ Exception)Úselfr Úop_nameZknown_patterns© r ú//tmp/tmp5hum_rxs/lib64/python/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 r c 3 s | ]}ˆ|ˆ @ d k V qdS )r Nr )Ú.0Úi)ÚmÚsymbolsr r ú ^ s z/LutBuilder.build_default_lut..é )Ú bytearrayÚrangeÚLUT_SIZEr )r r )r r r Úbuild_default_lut[ s zLutBuilder.build_default_lutc C s | j S )N)r )r r r r Úget_lut` s zLutBuilder.get_lutc s( t |ƒdkst‚dj‡ fdd„|D ƒƒS )z„string_permute takes a pattern and a permutation and returns the
string permuted according to the permutation list.
r Ú c 3 s | ]}ˆ | V qd S )Nr )r Úp)Úpatternr r r h s z-LutBuilder._string_permute..)ÚlenÚAssertionErrorÚjoin)r r% Zpermutationr )r% r Ú_string_permutec s zLutBuilder._string_permutec C sò ||fg}d|krN|d
d }x.t dƒD ]"}|j| j|d d tƒ|fƒ q(W d|krŽt|ƒ}x.|d|… D ]\}}|j| j|tƒ|fƒ qlW d|krît|ƒ}xN|d|… D ]>\}}|jddƒjd dƒjdd ƒ}dt|ƒ }|j||fƒ q¬W |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.Ú4r r r ÚMÚNÚ0ÚZÚ1éÿÿÿÿr0 )r Úappendr) ÚROTATION_MATRIXr&