Ë
    ÿ[;j¥  ã                   óž   — 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
             úkG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\skimage/future/manual_segmentation.pyÚ_mask_from_verticesr      sn   € Ü�8‰8�E¤Ô%€DÙ Ô	!™‘��1Š!˜€BÑ	!Ù Ô	!™‘��1Š!˜€BÑ	!Ü�R˜˜UÓ#�F€BˆØ€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Ý#á�h tÔ,€GÙ˜˜	°$¸eÔD€AØ×&Ñ& qÓ)€NØ‡H�H„JØÐó    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à×ÑÔØ�J‰J× Ñ Õ"ð  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Ñ#;Øà×ÑÔ!Øà�<‰<œ:Ò%Ø×Ñ˜eŸk™k¨5¯;©;Ð7Ô8á$Ø,×0Ñ0Ó2�Ø—‘”ô $ B¨	¸%À#¹+ÔGˆGØ!×(Ñ(¨Õ1à�\‰\œ[Ò(ÙØð
 !×'Ñ'¨	±!¨Ô5Ü*¨2¨yÀÔFˆNØ×!Ñ! .Ô1ð 1×4Ñ4Ó6ˆLØ×ÑÔ!Øš!�à�H‰H�Jð! )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   øè ø€ ð áC‰KˆAˆxô 	˜H e§k¡k°"°1 o°q×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   )rc   r    Ú
return_allr   rD   Úundo_buttonrY   Úlabelsr'   rA   rB   r(   rC   rV   rW   rX   s   ``      @@@@@@@@r   Úmanual_polygon_segmentationr|   !   s4  ÿù€ óL Ý#àÐØ€Nà€IØÐà‡z�z˜ÑÜÐIÓJÐJà�l‰l‹n�G€CˆØ×Ñ˜sÐÔ#Ø‡I�Iˆe˜&€IÔ!Ø‡O�OÔö#ð �|‰|Ò6Ó7€HØ×$Ñ$×+Ñ+¨H°hÓ?€KØ×Ñ˜5Ô!÷#ó #ðJ ‡J�J×ÑÐ/°ÔAà‡H�H�4€HÔóä$Ð%9ÀÕCó€Fñ Ü�x‰x˜ÓÐä”b—j‘j &¬"¯/©/¸!¸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Ô-Ü& r¨8¸5Ô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à‡z�z˜ÑÜÐIÓJÐJà�l‰l‹n�G€CˆØ×Ñ˜sÐÔ#Ø‡I�Iˆe˜&€IÔ!Ø‡O�OÔö#ð �|‰|Ò6Ó7€HØ×$Ñ$×+Ñ+¨H°hÓ?€KØ×Ñ˜5Ô!÷ð ð ×Ñ×$Ñ$ RÐ)<Ô=à‡H�H�4€HÔóä$Ð%9ÀÕCó€Fñ Ü�x‰x˜ÓÐä”b—j‘j &¬"¯/©/¸!¸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,   