o
    :ήc                     @   sB   d dl mZ ddlmZ ddlmZmZ dgZG dd deZdS )	   )dtype_range   )Plugin   )ClearColormapupdate_axes_image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   )redyellowgreencyanc                    s@   t t| jdi | d | _d | _d | _tt| j	 | _
d S )N )superr   __init___overlay_plot_overlaycmapsortedlistcolorskeyscolor_names)selfkwargs	__class__r   K/tmp/pip-target-vg8gfxp4/lib/python/skimage/viewer/plugins/overlayplugin.pyr      s
   zOverlayPlugin.__init__c                    s   t t| | d| _d S )Nr	   )r   r   attachcolor)r   image_viewerr   r   r   r   %   s   
zOverlayPlugin.attachc                 C      | j S N)r   r   r   r   r   overlay*      zOverlayPlugin.overlayc                 C   s   || _ | jj}|d u r|j| j d | _n| jd u 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    aximagesremover   r   dtypetypeimshowr   r   useblit_blit_manager
backgroundredraw)r   imager(   r&   r'   r   r   r   r$   .   s   



c                 C   r!   r"   )_colorr#   r   r   r   r   A   r%   zOverlayPlugin.colorc                 C   sj   t |tr|| jvrtd| | j| }|| _| j| }t|| _| jd ur.| j	| j | j
  d S )Nz&%s not defined in OverlayPlugin.colors)
isinstancestrr   
ValueErrorr3   r   r   r   r   set_cmapr    r1   )r   indexnamergbr   r   r   r   E   s   




c                 C   r!   )zcReturn filtered image.

        This "filtered image" is used when saving from the plugin.
        r$   r#   r   r   r   filtered_imageU   s   zOverlayPlugin.filtered_imagec                 C   s
   || _ dS )z?Display filtered image as an overlay on top of image in viewer.Nr;   )r   r2   r   r   r   display_filtered_image]   s   
z$OverlayPlugin.display_filtered_imagec                    s   d | _ tt| | d S r"   )r$   r   r   
closeEvent)r   eventr   r   r   r>   a   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
        Nr;   r#   r   r   r   outputf   s   
	zOverlayPlugin.output)__name__
__module____qualname____doc__r   r   r   propertyr$   setterr   r<   r=   r>   r@   __classcell__r   r   r   r   r   	   s,    




N)	
util.dtyper   baser   utilsr   r   __all__r   r   r   r   r   <module>   s
   