
    |h                         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y)    )reduceN   )polygon)require      c                     t        j                  |t              }| D cg c]  \  }}|	 }}}| D cg c]  \  }}|	 }}}t        |||      \  }}	||||	f<   |S c c}}w c c}}w )N)dtype)npzerosintr   )
verticesshapelabelmaskxyprpcrrccs
             a/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/future/manual_segmentation.py_mask_from_verticesr      sl    88E%D 	!1!	!B	! 	!1!	!B	!RU#FBDRLK	 
"	!s
   AA#
matplotlibz>=3.3c                     ddl m} ddlm} dd lm}  ||d      } ||gd|      }| j                  |      }|j                          |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_polygonr+      sF    *6#ht,G	$eDA&&q)NHHJ    c           
         	
 ddl }ddlm g 
g g g  j                  dvrt	        d      j                         \  		j                  d       j                   d       j                          	
fd	}	j                  g d
      |j                  j                  d      }|j                  |       
fd}	j                  j                  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 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                      rKj                          j                         }|j                          j                  j                          y y Npopremovecanvas	draw_idleargskwargs	last_polyfiglist_of_vertex_listspolygons_drawns      r   _undoz*manual_polygon_segmentation.<locals>._undoX   A     $$&&**,IJJ  "  r,   g333333?g?333333?rG      ⟲c                 Z   | j                   | j                   u ry j                         ry | j                  t        k(  rlj	                  | j
                  | j                  g       
r 
j                         }|j                          t        dz        }
j	                  |       y | j                  t        k(  rlsy j	                  d d         t              }	j	                  |       
j                         }|j                          d d = j                          y y )Ngffffff?r    )inaxesget_navigate_modebutton
LEFT_CLICKappendxdataydatar9   r:   r+   RIGHT_CLICKr&   )eventpolyr   r*   preview_polyr    r'   rB   r(   rC   preview_polygon_drawn	temp_listundo_poss        r   _extend_polygonz4manual_polygon_segmentation.<locals>._extend_polygone   s    <<5<<8#;!<<:%ekk5;;78$,002 $B	%#+GG!((1\\[(
 !''	!5*2yFN!!.1 1446L!!HHJ! )r,   button_press_eventTblockc              3   X   K   | ]!  \  }}t        |j                  d d |       # y wNr   r   r   .0ir   images      r   	<genexpr>z.manual_polygon_segmentation.<locals>.<genexpr>   0      Ax 	Hekk"1oq9   '*r   startr   )r   r#   r$   ndim
ValueErrorsubplotssubplots_adjustimshowset_axis_offadd_axeswidgetsButton
on_clickedr;   mpl_connectshow	enumerater   stackr   maximumbroadcast_tor   )rc   r    
return_allr   rD   undo_buttonrY   labelsr'   rA   rB   r(   rC   rV   rW   rX   s   ``      @@@@@@@@r   manual_polygon_segmentationr|   !   s4   L #NIzzIJJllnGCs#IIe&I!OO# ||67H$$++Hh?K5!# #J JJ/AHH4H$%9CF xxbjj&"//!U[[!_*MNNr,   c           
         	
 ddl }ddlm g g  j                  dvrt	        d      j                         \  
	
j                  d       	j                   d       	j                          
fd	}
j                  g d
      }|j                  j                  |d      }|j                  |       	fd}|j                  j                  	|       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   Nr.   r/   r0   r1   r3   r4   c                      rKj                          j                         }|j                          j                  j                          y y r7   r8   r=   s      r   rD   z(manual_lasso_segmentation.<locals>._undo   rE   r,   rF   rH   c                     t        |       dk  ry j                  |        t        |       }j                  |       j                          y )Nr   rJ   )lenrO   r+   r&   )r   r*   r    r'   rB   r(   rC   s     r   _on_lasso_selectionz6manual_lasso_segmentation.<locals>._on_lasso_selection   sE    x=1##H-&r85An-
r,   Tr[   c              3   X   K   | ]!  \  }}t        |j                  d d |       # y wr^   r_   r`   s      r   rd   z,manual_lasso_segmentation.<locals>.<genexpr>   re   rf   r   rg   r   )r   r#   r$   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   LassoSelectorrt   ru   r   rv   r   rw   rx   r   )rc   r    ry   r   rD   rX   rz   r   r{   r'   rA   rB   r(   rC   s   ``       @@@@@r   manual_lasso_segmentationr      s)   J #NzzIJJllnGCs#IIe&I!OO# ||67H$$++Hh?K5!  $$R)<=HH4H$%9CF xxbjj&"//!U[[!_*MNNr,   )皙?)r   F)	functoolsr   numpyr   r&   r   _shared.version_requirementsr   rN   rR   r   r+   r|   r    r,   r   <module>r      s|       2 
 	w	  	 	wsO  sOl 	wRO  ROr,   