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]ã @shddlZddlmZmZdZddddddd d d g Zd ddd ddd ddg ZGd d „d ƒZGdd„dƒZdS)éNé)ÚImageÚ _imagingmorphé éééééééc@sJeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)Ú 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() NcCsr|dk r||_ng|_d|_|dk rnddgdgddgdgddgdddgd œ}||krdtd |d ƒ‚|||_dS) 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__cCs|j|7_dS)N)r)rrrrrÚ add_patternsXszLutBuilder.add_patternscs.ddg‰d‰t‡‡fdd„ttƒDƒƒ|_dS)Nrrr c3s|]}ˆ|ˆ@dkVqdS)rNr)Ú.0Úi)ÚmÚsymbolsrrú ^sz/LutBuilder.build_default_lut..é)Ú bytearrayÚrangeÚLUT_SIZEr)rr)rrrÚbuild_default_lut[szLutBuilder.build_default_lutcCs|jS)N)r)rrrrÚget_lut`szLutBuilder.get_lutcs(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Úc3s|]}ˆ|VqdS)Nr)rÚp)Úpatternrrrhsz-LutBuilder._string_permute..)ÚlenÚAssertionErrorÚjoin)rr%Z permutationr)r%rÚ_string_permutecszLutBuilder._string_permutec Csò||fg}d|krN|d d}x.tdƒD]"}|j|j|d dtƒ|fƒq(Wd|krŽt|ƒ}x.|d|…D]\}}|j|j|tƒ|fƒqlWd|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.Ú4rr rÚMÚNÚ0ÚZÚ1éÿÿÿÿr0)rÚappendr)ÚROTATION_MATRIXr&Ú MIRROR_MATRIXÚreplaceÚint) rZ basic_patternÚoptionsZ basic_resultrÚresrÚnr%rrrÚ_pattern_permutejs"   zLutBuilder._pattern_permutec CsL|jƒg}x~|jD]t}tjd|jddƒƒ}|s@td|dƒ‚|jdƒ}|jdƒ}t|jdƒƒ}|jd dƒjddƒ}||j|||ƒ7}qWxFt |ƒD]:\}}|d jd d ƒjd d ƒ}tj |ƒ}||df||<q–Wxpt t ƒD]d}t |ƒdd…}ddt|ƒ|ddd…}x0|D](\}} |j|ƒ�rd dg| |j|<�qWqÞW|jS)zlCompile all patterns into a morphology lut. TBD :Build based on (file) morphlut:modify_lut z(\w*):?\s*\((.+?)\)\s*->\s*(\d)Ú r#zSyntax error in pattern "ú"rr rú rÚ.ÚXz[01]Nr-rr0)r!rÚreÚsearchr4rÚgroupr5r9Ú enumerateÚcompilerr Úbinr&Úmatchr) rrr$rr6r%ÚresultrZ bitpatternÚrrrrÚ build_lutˆs,     zLutBuilder.build_lut)NN) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrr!r"r)r9rHrrrrr s" r c@sJeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)ÚMorphOpz*A class for binary morphological operatorsNcCs<||_|dk r t|d�jƒ|_n|dk r8t|d�jƒ|_dS)z&Create a binary morphological operatorN)r)r)rr rH)rrrrrrrr¶s zMorphOp.__init__cCsZ|jdkrtdƒ‚|jdkr$tdƒ‚tj|j|jdƒ}tjt |jƒ|j 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 imageNzNo operator loadedÚLzImage mode must be L) rrÚmodeÚ ValueErrorrÚnewÚsizerÚapplyÚbytesÚimÚid)rÚimageZoutimageÚcountrrrrS¾s  z MorphOp.applycCs:|jdkrtdƒ‚|jdkr$tdƒ‚tjt|jƒ|jjƒ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`.NzNo operator loadedrNzImage mode must be L) rrrOrPrrErTrUrV)rrWrrrrEÌs   z MorphOp.matchcCs |jdkrtdƒ‚tj|jjƒ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`.rNzImage mode must be L)rOrPrÚ get_on_pixelsrUrV)rrWrrrrYÙs zMorphOp.get_on_pixelsc CsDt|dƒ�}t|jƒƒ|_WdQRXt|jƒtkr@d|_tdƒ‚dS)z!Load an operator from an mrl fileÚrbNzWrong size operator file!)ÚopenrÚreadrr&r r)rÚfilenameÚfrrrÚload_lutãs  zMorphOp.load_lutc Cs8|jdkrtdƒ‚t|dƒ�}|j|jƒWdQRXdS)zSave an operator to an mrl fileNzNo operator loadedÚwb)rrr[Úwrite)rr]r^rrrÚsave_lutìs  zMorphOp.save_lutcCs ||_dS)z#Set the lut from an external sourceN)r)rrrrrÚset_lutószMorphOp.set_lut)NNN) rIrJrKrLrrSrErYr_rbrcrrrrrM³s    rMi) r?r#rrr r2r3r rMrrrrÚs