B
    \                 @   sb   d dl mZ ddlmZ ddlmZ ddlmZmZ d dl	Z	dd	l
mZ d
gZG dd
 d
eZdS )    )warn   )dtype_range   )Plugin   )ClearColormapupdate_axes_imageN)is_installedOverlayPluginc                   s   e Zd ZdZdddddZ fddZ fd	d
Zedd Zej	dd Zedd Z
e
j	dd Z
edd Zdd Z fddZdd Z  ZS )r   a  Plugin for ImageViewer that displays an overlay on top of main image.

    The base Plugin class displays the filtered image directly on the viewer.
    OverlayPlugin will instead overlay an image with a transparent colormap.

    See base Plugin class for additional details.

    Attributes
    ----------
    overlay : array
        Overlay displayed on top of image. This overlay defaults to a color map
        with alpha values varying linearly from 0 to 1.
    color : int
        Color of overlay.
    )r   r   r   )r   r   r   )r   r   r   )r   r   r   )ZredZyellowZgreenZcyanc                sV   t ddsd}tt| tt| jf | d | _d | _d | _t	t
| j | _d S )NZ
matplotlibz>=1.2z-Matplotlib >= 1.2 required for OverlayPlugin.)r
   r   RuntimeWarningsuperr   __init___overlay_plot_overlaycmapsortedlistcolorskeyscolor_names)selfkwargsmsg)	__class__ Clib/python3.7/site-packages/skimage/viewer/plugins/overlayplugin.pyr   #   s    
zOverlayPlugin.__init__c                s   t t| | d| _d S )Nr   )r   r   attachcolor)r   image_viewer)r   r   r   r   -   s    zOverlayPlugin.attachc             C   s   | j S )N)r   )r   r   r   r   overlay2   s    zOverlayPlugin.overlayc             C   s   || _ | jj}|d kr,|j| j d | _n>| jd kr^t|jj \}}|j	|| j
||d| _nt| j| | jjr|d | jj_| j  d S )N)r   vminvmax)r   r   axZimagesremover   r   ZdtypetypeZimshowr   r	   ZuseblitZ_blit_managerZ
backgroundredraw)r   imager#   r!   r"   r   r   r   r    6   s    


c             C   s   | j S )N)_color)r   r   r   r   r   I   s    zOverlayPlugin.colorc             C   sn   t |tjr$|| jkr$td| n
| j| }|| _| j| }t|| _| j	d k	r`| j	
| j | j  d S )Nz&%s not defined in OverlayPlugin.colors)
isinstancesixZstring_typesr   
ValueErrorr(   r   r   r   r   Zset_cmapr   r&   )r   indexnameZrgbr   r   r   r   M   s    




c             C   s   | j S )zcReturn filtered image.

        This "filtered image" is used when saving from the plugin.
        )r    )r   r   r   r   filtered_image]   s    zOverlayPlugin.filtered_imagec             C   s
   || _ dS )z?Display filtered image as an overlay on top of image in viewer.N)r    )r   r'   r   r   r   display_filtered_imagee   s    z$OverlayPlugin.display_filtered_imagec                s   d | _ tt| | d S )N)r    r   r   
closeEvent)r   Zevent)r   r   r   r0   i   s    zOverlayPlugin.closeEventc             C   s
   | j dfS )zReturn the overlaid image.

        Returns
        -------
        overlay : array, same shape as image
            The overlay currently displayed.
        data : None
        N)r    )r   r   r   r   outputn   s    	zOverlayPlugin.output)__name__
__module____qualname____doc__r   r   r   propertyr    setterr   r.   r/   r0   r1   __classcell__r   r   )r   r   r      s   
)warningsr   Z
util.dtyper   baser   Zutilsr   r	   r*   Z_shared.version_requirementsr
   __all__r   r   r   r   r   <module>   s   