
    0-Ph                         d dl mZ d dlZddlmZ ddlmZ dZdZ	d Z
 ed	d
          dd            Z ed	d
          dd            Z ed	d
          dd            ZdS )    )reduceN   )polygon)require      c                     t          j        |t                    }d | D             }d | D             }t          |||          \  }}||||f<   |S )N)dtypec                     g | ]\  }}|S  r   .0xys      b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/future/manual_segmentation.py
<listcomp>z'_mask_from_vertices.<locals>.<listcomp>       	!	!	!1!	!	!	!    c                     g | ]\  }}|S r   r   r   s      r   r   z'_mask_from_vertices.<locals>.<listcomp>   r   r   )npzerosintr   )verticesshapelabelmaskprpcrrccs           r   _mask_from_verticesr!      sc    8E%%%D	!	!	!	!	!B	!	!	!	!	!BRU##FBDRLKr   
matplotlibz>=3.3皙?c                     ddl m} ddlm} dd lm}  ||d          } ||gd|          }|                     |          }|                                 |S )Nr   )Polygon)PatchCollectionT)closed)match_originalalpha)matplotlib.patchesr%   matplotlib.collectionsr&   matplotlib.pyplotpyplotadd_collectiondraw)	axr   r)   r%   r&   pltr   ppolygon_objects	            r   _draw_polygonr4      s    ******666666######ght,,,G	$eDDDA&&q))NHHJJJr   Fc           
         	
 ddl }ddlm g 
g g g  j        dvrt	          d                                          \  		                    d                                d                                            	
fd	}		                    g d
          |j
                            d          }|                    |           
fd}	j                            d|                               d            fdt!          
d          D             }|rt#          j        |          S t'          t"          j        |t#          j        d j        dd                             S )a  Return a label image based on polygon selections made with the mouse.

    Parameters
    ----------
    image : (M, N[, 3]) array
        Grayscale or RGB image.

    alpha : float, optional
        Transparency value for polygons drawn over the image.

    return_all : bool, optional
        If True, an array containing each separate polygon drawn is returned.
        (The polygons may overlap.) If False (default), latter polygons
        "overwrite" earlier ones where they overlap.

    Returns
    -------
    labels : array of int, shape ([Q, ]M, N)
        The segmented regions. If mode is `'separate'`, the leading dimension
        of the array corresponds to the number of regions that the user drew.

    Notes
    -----
    Use left click to select the vertices of the polygon
    and right click to confirm the selection once all vertices are selected.

    Examples
    --------
    >>> from skimage import data, future
    >>> import matplotlib.pyplot as plt  # doctest: +SKIP
    >>> camera = data.camera()
    >>> mask = future.manual_polygon_segmentation(camera)  # doctest: +SKIP
    >>> fig, ax = plt.subplots()  # doctest: +SKIP
    >>> ax.imshow(mask)           # doctest: +SKIP
    >>> plt.show()                # doctest: +SKIP
    r   Nr   r   .Only 2D grayscale or RGB images are supported.皙?bottomgraycmapc                      rW                                                                   }|                                 j                                         d S d S Npopremovecanvas	draw_idleargskwargs	last_polyfiglist_of_vertex_listspolygons_drawns      r   _undoz*manual_polygon_segmentation.<locals>._undoX   d     	# $$&&&&**,,IJ  """""	# 	#r   g333333?g?333333?rO      ⟲c                    | j         	| j         u rd S                                 rd S | j        t          k    rw                    | j        | j        g           
r(
                                }|                                 t          dz            }
                    |           d S | j        t          k    rsd S                     d d                     t                    }	                    |           
                                }|                                 d d =                                  d S d S )Ngffffff?r)   )inaxesget_navigate_modebutton
LEFT_CLICKappendxdataydatarA   rB   r4   RIGHT_CLICKr/   )eventpolyr   r3   preview_polyr)   r0   rJ   r1   rK   preview_polygon_drawn	temp_listundo_poss        r   _extend_polygonz4manual_polygon_segmentation.<locals>._extend_polygone   sb   <5<8#;#;F!! 	F<:%%ek5;7888$ ,0022 $B	%#+GGGG!((11111\[(( 
 !''	!!!555*2yFFFN!!.111 14466L!!!!!!HHJJJJJ! )(r   button_press_eventTblockc              3   Z   K   | ]%\  }}t          |j        d d         |          V  &d S Nr   r!   r   r   ir   images      r   	<genexpr>z.manual_polygon_segmentation.<locals>.<genexpr>   Q        Ax 	Hek"1"oq99     r   r   startr   )r"   r,   r-   ndim
ValueErrorsubplotssubplots_adjustimshowset_axis_offadd_axeswidgetsButton
on_clickedrC   mpl_connectshow	enumerater   stackr   maximumbroadcast_tor   )rj   r)   
return_allr"   rL   undo_buttonra   labelsr0   rI   rJ   r1   rK   r^   r_   r`   s   ``      @@@@@@@@r   manual_polygon_segmentationr   !   s   L ######NIzIJJJllnnGCs###IIe&I!!!OO# # # # # # # ||66677H$++Hh??K5!!!# # # # # # # # # # # #J J/AAAHH4H   $%9CCC  F  Oxbj&"/!U[!_*M*MNNNr   c           
         	
 ddl }ddlm g g  j        dvrt	          d                                          \  
	
                    d           	                     d           	                                 
fd	}
	                    g d
          }|j
                            |d          }|                    |           	fd}|j
                            	|                               d            fdt          d          D             }|rt!          j        |          S t%          t           j        |t!          j        d j        dd                             S )a  Return a label image based on freeform selections made with the mouse.

    Parameters
    ----------
    image : (M, N[, 3]) array
        Grayscale or RGB image.

    alpha : float, optional
        Transparency value for polygons drawn over the image.

    return_all : bool, optional
        If True, an array containing each separate polygon drawn is returned.
        (The polygons may overlap.) If False (default), latter polygons
        "overwrite" earlier ones where they overlap.

    Returns
    -------
    labels : array of int, shape ([Q, ]M, N)
        The segmented regions. If mode is `'separate'`, the leading dimension
        of the array corresponds to the number of regions that the user drew.

    Notes
    -----
    Press and hold the left mouse button to draw around each object.

    Examples
    --------
    >>> from skimage import data, future
    >>> import matplotlib.pyplot as plt  # doctest: +SKIP
    >>> camera = data.camera()
    >>> mask = future.manual_lasso_segmentation(camera)  # doctest: +SKIP
    >>> fig, ax = plt.subplots()  # doctest: +SKIP
    >>> ax.imshow(mask)           # doctest: +SKIP
    >>> plt.show()                # doctest: +SKIP
    r   Nr6   r7   r8   r9   r;   r<   c                      rW                                                                   }|                                 j                                         d S d S r?   r@   rE   s      r   rL   z(manual_lasso_segmentation.<locals>._undo   rM   r   rN   rP   c                     t          |           dk     rd S                     |            t          |           }                    |                                            d S )Nr   rR   )lenrW   r4   r/   )r   r3   r)   r0   rJ   r1   rK   s     r   _on_lasso_selectionz6manual_lasso_segmentation.<locals>._on_lasso_selection   sf    x==1F##H---&r85AAAn---




r   Trc   c              3   Z   K   | ]%\  }}t          |j        d d         |          V  &d S rf   rg   rh   s      r   rk   z,manual_lasso_segmentation.<locals>.<genexpr>   rl   r   r   rm   r   )r"   r,   r-   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   LassoSelectorrz   r{   r   r|   r   r}   r~   r   )rj   r)   r   r"   rL   r`   r   r   r   r0   rI   rJ   r1   rK   s   ``       @@@@@r   manual_lasso_segmentationr      s   J ######NzIJJJllnnGCs###IIe&I!!!OO# # # # # # # ||66677H$++Hh??K5!!!         $$R)<===HH4H   $%9CCC  F  Oxbj&"/!U[!_*M*MNNNr   )r#   )r#   F)	functoolsr   numpyr   r/   r   _shared.version_requirementsr   rV   rZ   r!   r4   r   r   r   r   r   <module>r      s                   2 2 2 2 2 2 
   	w	 	 	  	 	wsO sO sO  sOl 	wRO RO RO  RO RO ROr   