
    9i                         S SK Jr  S SKrSSKJr  SSKJr  SrSr	S r
\" S	S
5      SS j5       r\" S	S
5      SS j5       r\" S	S
5      SS j5       rg)    )reduceN   )polygon)require      c                     [         R                  " U[        S9nU  VVs/ s H  u  pEUPM	     nnnU  VVs/ s H  u  pEUPM	     nnn[        XgU5      u  pX#X4'   U$ s  snnf s  snnf )N)dtype)npzerosintr   )
verticesshapelabelmaskxyprpcrrccs
             b/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/future/manual_segmentation.py_mask_from_verticesr      sb    88E%D 	!!B	! 	!!B	!RU#FBLK	 
"	!s
   AA!
matplotlibz>=3.3c                     SSK Jn  SSKJn  SS KJn  U" USS9nU" U/SUS9nU R                  U5      nUR                  5         U$ )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           
        ^ ^^^	^
^^^^^ SSK nSSKJm  / m
/ m/ m/ mT R                  S;  a  [	        S5      eTR                  5       u  m	mT	R                  SS9  TR                  T SS9  TR                  5         U	U
U4S	 jnT	R                  / S
Q5      mUR                  R                  TS5      nUR                  U5        UUU
UUUUU4S jnT	R                  R                  SU5        TR                  SS9  U 4S j[!        T
SS9 5       nU(       a  ["        R$                  " U5      $ ['        ["        R(                  U["        R*                  " ST R,                  SS 5      5      $ )ay  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                     > T(       aK  TR                  5         TR                  5       nUR                  5         TR                  R                  5         g g Npopremovecanvas	draw_idleargskwargs	last_polyfiglist_of_vertex_listspolygons_drawns      r   _undo*manual_polygon_segmentation.<locals>._undoX   A     $$&&**,IJJ  "  r,   g333333?g?333333?rH      ⟲c                 t  > U R                   b  U R                   TL a  g TR                  5       (       a  g U R                  [        :X  an  TR	                  U R
                  U R                  /5        T
(       a   T
R                  5       nUR                  5         [        TTTS-  S9nT
R	                  U5        g U R                  [        :X  an  T(       d  g TR	                  TS S  5        [        TTTS9nT	R	                  U5        T
R                  5       nUR                  5         TS S 2	 TR                  5         g g )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_polygon4manual_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   \   >#    U  H!  u  p[        UTR                  S S U5      v   M#     g 7fNr   r   r   .0ir   images      r   	<genexpr>.manual_polygon_segmentation.<locals>.<genexpr>   0      CKA 	Hekk"1oq99C   ),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   )re   r    
return_allr   rD   undo_buttonrZ   labelsr'   rA   rB   r(   rC   rW   rX   rY   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           
        ^ ^^	^
^^^ SSK nSSKJm  / m/ mT R                  S;  a  [	        S5      eTR                  5       u  m
m	T
R                  SS9  T	R                  T SS9  T	R                  5         U
UU4S	 jnT
R                  / S
Q5      nUR                  R                  US5      nUR                  U5        UU	UUU4S jnUR                  R                  T	U5        TR                  SS9  U 4S j[        TSS9 5       nU(       a  [         R"                  " U5      $ [%        [         R&                  U[         R(                  " ST R*                  SS 5      5      $ )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                     > T(       aK  TR                  5         TR                  5       nUR                  5         TR                  R                  5         g g r7   r8   r=   s      r   rD   (manual_lasso_segmentation.<locals>._undo   rF   r,   rG   rI   c                    > [        U 5      S:  a  g TR                  U 5        [        TU TS9nTR                  U5        TR                  5         g )Nr   rK   )lenrP   r+   r&   )r   r*   r    r'   rB   r(   rC   s     r   _on_lasso_selection6manual_lasso_segmentation.<locals>._on_lasso_selection   sE    x=1##H-&r85An-
r,   Tr]   c              3   \   >#    U  H!  u  p[        UTR                  S S U5      v   M#     g 7fr`   ra   rb   s      r   rf   ,manual_lasso_segmentation.<locals>.<genexpr>   rh   ri   r   rj   r   )r   r#   r$   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   LassoSelectorrw   rx   r   ry   r   rz   r{   r   )re   r    r|   r   rD   rY   r}   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   rO   rS   r   r+   r   r    r,   r   <module>r      s|       2 
 	w	  	 	wsO  sOl 	wRO  ROr,   