ó
±éRc           @  s,   d  d l  m Z d  d l Z d d „ Z d S(   iÿÿÿÿ(   t   print_functionNi    c         C  sç  |  j  t j k s t ‚ t j |  j d |  j d d f t j ƒ } xœt d d ƒ D]‹} |  d d … d d … | f } | d d … d d … | f } t j | d d ƒd } | rÛd } x" t d ƒ D] } | | | } qÊ W| | d }	 xg t d ƒ D]Y }
 |	 | |
 k r.|	 | |
 }	 d | |
 <n | |
 |	 | |
 <d }	 |	 d k rý Pqý qý W| | d }	 xp t d d	 d	 ƒ D]Y } |	 | | k r¬|	 | | }	 d | | <n | | |	 | | <d }	 |	 d k r{Pq{q{Wn  x" t d ƒ D] }
 | |
 rèPqèqèWx( t d d	 d	 ƒ D] } | | rPqqW| |
 k rV| | d d … d d … f <qT d
 | |
 } |
 | } t j	 d d t j
 ƒ} | | 9} | | 7} | j d d ƒ } | j t j ƒ } | | | d d … d d … f <qT W| S(   sf   
    Maximize image contrast, based on histogram.  This completely
    ignores the alpha channel.
    i    i   i   Nt   binsi   id   iÿ   iÿÿÿÿg     ào@t   dtype(   R   t   npt   uint8t   AssertionErrort   emptyt   shapet   xranget	   histogramt   ranget   aranget   floatt   clipt   astype(   t   imaget   cutofft   output_imaget   it   planet   output_planet   ht   nt   ixt   cutt   lot   hit   scalet   offsett   lut(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/image_util.pyt   autocontrast$   sZ    ,



$(   t
   __future__R    t   numpyR   R   (    (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/image_util.pyt   <module>    s   