mò
”pDc           @   s^   d  k  Td k Z d k Z d k l Z l Z d „  Z d f  d „  ƒ  YZ d „  Z d „  Z	 d S(   (   t   *N(   s   logs   ceilc         C   s)   y t  i |  ƒ } t SWn t Sn Xd  S(   N(   t   Imaget   opent
   image_namet   Imt   Truet   False(   R   R   (    (    t&   /home/lathuili/fractal/box_counting.pyt
   test_image   s
    t   Box_Countingc           B   st   t  Z d  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z RS(   s$   Module to count the box in one imagec         C   s8   | d  j o |  i | ƒ n |  i d ƒ d |  _ d  S(   Nt   pairf1.2(   R   t   Nonet   selft	   set_imaget
   set_methodt	   Precision(   R   R   (    (    R   t   __init__   s    c         C   s„   y t  i | ƒ i d ƒ |  _ Wn t | ‚ n X|  i i d } |  i i d } | } | | j o
 | } n | d d |  _
 d  S(   Nt   1i    i   i   (   R   R   R   t   convertR   R   t   InvalidImaget   sizet   largeurt   hauteurt   Size_max_box(   R   R   R   R   R   (    (    R   R      s    
c         C   s0   | d d d g j o | |  _  n
 t d ‚ d  S(   Nt   allR
   t   exponentials   invalid method(   t   methodR   t   InvalidArgument(   R   R   (    (    R   R   '   s    c         C   s   |  i S(   N(   R   R   (   R   (    (    R   t
   get_method-   s    c         C   s  |  i d j o t d |  i ƒ |  _ nÛ |  i d j oI g  } t d |  i ƒ D]" } | d d j o | | qP qP ~ |  _ n‚ |  i d j oh d „  } | g  } t d t t	 |  i |  i
 ƒ ƒ ƒ D]  } | t t |  i
 | ƒ ƒ qÇ ~ ƒ |  _ n
 t d ‚ d  S(	   NR   i   R
   i    R   c         C   s1   t  g  } |  D] } | | d f q ~ ƒ i ƒ  S(   Ni    (   t   dictt   _[1]t   listt   it   keys(   R   R   R    (    (    R   t   unique6   s    i   s   invalid method(   R   R   t   rangeR   t   BoxesR   t   xR"   t   intt   logR   R    t   ceilR   (   R   R    R   R%   R"   (    (    R   t	   set_boxes0   s    I	_c         C   s   | |  _ d  S(   N(   t	   precisionR   R   (   R   R*   (    (    R   t   set_precision>   s    c         C   s   |  i S(   N(   R   R   (   R   (    (    R   t   get_precisionA   s    c         C   s   |  i ƒ  |  i ƒ  d  S(   N(   R   R)   t   Nb_BGW_for_each_box(   R   (    (    R   t   computeD   s    
c         C   s"   | i ƒ  |  i ƒ  | i ƒ  d  S(   N(   t   datalockt   releaseR   R.   t   acquire(   R   R/   (    (    R   t   compute_with_lockI   s    

c         C   sY   g  } xL |  i i ƒ  D]; } |  i | \ } } } | i t	 | ƒ t	 | ƒ f ƒ q W| S(   N(
   t   PlotR   t   ComputationR!   t   boxt   whitet   greyt   blackt   appendR'   (   R   R5   R3   R7   R8   R6   (    (    R   t   plotP   s     #c   
      C   sr  |  i i d } |  i i d } t | | |  i ƒ }	 xð t d | ƒ D]ß } xÖ t d | ƒ D]Å } |  i i | | f ƒ } x¤ |  i D]™ } |	 | } | | | | | } | d j pf | d j o$ | | | | | | <| |	 | <q| | j p$ d | | | | | <| |	 | <qqƒ qƒ Wq[ WqE W|	 |  _ x: |  i i ƒ  D]) } t |  i | | | | ƒ |  i | <qAWd  S(   Ni    i   iÿÿÿÿ(   R   R   R   t   widtht   heightt   Structure_CreationR$   t	   StructureR#   R    t   jt   getpixelt   pixelR5   t   tablet	   color_boxR4   R!   t	   count_box(
   R   R5   RC   R    R?   R<   R;   RB   RA   R>   (    (    R   R-   W   s.      
 
	 (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R)   R+   R,   R.   R2   R:   R-   (    (    (    R   R	      s    									c            s:   h  } ‡ ‡  d †  } x | D] } | | ƒ | | <q W| S(   Nc            s]   g  g ˆ |  d |  } x= t ˆ |  d |  ƒ D]# } d g ˆ  |  d |  | | <q2 W| S(   Ni   iÿÿÿÿ(   R;   R5   t   resultR#   R    R<   (   R5   R    RH   (   R<   R;   (    R   t   Table_creationq   s
     !(   t	   structureRI   R$   R5   (   R;   R<   R$   R5   RJ   RI   (    (   R;   R<   R   R=   o   s     c            s4   ‡ ‡ ‡ ‡  d †  } | d ƒ | d ƒ | d ƒ f S(   Nc            s>  ˆ ˆ  } | d j o
 d } n | d ˆ  } ˆ ˆ  } | d j o
 d } n | d ˆ  } d } xm ˆ d d !D]^ } x0 | d d !D]! } | |  j o | d 7} q† q† W| d } | |  j o | | 7} qr qr Wˆ d } x0 | d d !D]! } | |  j o | | 7} qì qì W| d } | |  j o | | | 7} n | S(   Ni    i   f0.0iÿÿÿÿ(
   R;   R5   t   width_poucentR<   t   height_poucentt   resRB   R    R?   t   element(   RN   R    RM   R?   RK   RL   (   R5   R<   R;   RB   (    R   t   count_2d|   s6    



  

 
iÿ   i   i    (   RO   (   RB   R5   R;   R<   RO   (    (   RB   R5   R;   R<   R   RD   {   s    (
   t   my_exceptionsR   t   syst   mathR'   R(   R   R	   R=   RD   (   R	   R'   R=   R   R(   RQ   R   RD   (    (    R   t   ?   s   				^	
