§
    à©ºjs
  ã                  ó¼   — d Z ddlmZ ddlmZ ddlZddlmZ	 g d¢Z
e	j        Ze	j        Ze	j        Ze	j        Ze	j        Ze	j        Zdd„Zdd„Zdd„Zdd„Zddd„ZdS )uÿ  RLE mask utilities â€” the ``pycocotools.mask`` surface.

Same functions, same argument shapes, same return dtypes, same ``bytes``
``counts``. The implementation is a Rust port of ``maskApi.c`` that reproduces
the C arithmetic exactly, including the parts that look like bugs (see
``rust/ufcoco-core/src/rle.rs``).

Everything below is a thin dispatcher: ``pycocotools.mask`` itself is only a
few lines over ``pycocotools._mask``, and the list-vs-single-object rules it
implements are load-bearing for callers.
é    )Úannotations)ÚAnyNé   )Ú_ufcoco)ÚencodeÚdecodeÚmergeÚareaÚtoBboxÚiouÚfrPyObjectsÚfrBboxÚfrPolyÚfrUncompressedRLEÚ
toBoundaryÚbimaskú
np.ndarrayÚreturnr   c                óì   — | j         dk    rt          j        | ¦  «        S | j         dk    r<| j        \  }}t          j        |                      ||dfd¬¦  «        ¦  «        d         S t          d¦  «        ‚)zÚEncode a binary mask, or a stack of them, as RLE.

    A 2-D ``(h, w)`` input returns one RLE dict; a 3-D ``(h, w, n)`` input
    returns a list of ``n`` dicts. That asymmetry is pycocotools' and is
    preserved.
    é   é   r   ÚF)Úorderr   z)encode() expects a 2-D or 3-D uint8 array)ÚndimÚ_maskr   ÚshapeÚreshapeÚ
ValueError)r   ÚhÚws      új/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultrafast_pycocotools/mask.pyr   r   +   ss   € ð „{�aÒÐÝŒ|˜FÑ#Ô#Ð#Ø„{�aÒÐØŒ|‰ˆˆ1ÝŒ|˜FŸNšN¨A¨q°!¨9¸C˜NÑ@Ô@ÑAÔAÀ!ÔDÐDÝ
Ð@Ñ
AÔ
AÐAó    ÚrleObjsc                ó˜   — t          | t          ¦  «        rt          j        | ¦  «        S t          j        | g¦  «        dd…dd…df         S )z3Decode RLE back to a binary mask, in Fortran order.Nr   )Ú
isinstanceÚlistr   r   ©r#   s    r!   r   r   :   sI   € å�'�4Ñ Ô ð %ÝŒ|˜GÑ$Ô$Ð$ÝŒ<˜˜	Ñ"Ô" 1 1 1 a a a¨ 7Ô+Ð+r"   c                óŠ   — t          | t          ¦  «        rt          j        | ¦  «        S t          j        | g¦  «        d         S )z/Mask area(s), as ``uint32`` like the reference.r   )r%   r&   r   r
   r'   s    r!   r
   r
   A   s;   € å�'�4Ñ Ô ð #ÝŒz˜'Ñ"Ô"Ð"ÝŒ:�w�iÑ Ô  Ô#Ð#r"   c                óŠ   — t          | t          ¦  «        rt          j        | ¦  «        S t          j        | g¦  «        d         S )z;Tight bounding box(es) ``[x, y, w, h]`` around the mask(s).r   )r%   r&   r   r   r'   s    r!   r   r   H   s;   € å�'�4Ñ Ô ð %ÝŒ|˜GÑ$Ô$Ð$ÝŒ<˜˜	Ñ"Ô" 1Ô%Ð%r"   ç{®Gáz”?Údilation_ratioÚfloatc                óŽ   — t          | t          ¦  «        rt          j        | |¦  «        S t          j        | g|¦  «        d         S )uA  Boundary mask(s) for Boundary IoU (Cheng et al., CVPR 2021).

    Extension â€” pycocotools has no equivalent. The boundary is the mask minus
    its erosion by ``round(dilation_ratio * image_diagonal)`` pixels, computed
    on a zero-padded canvas so a mask touching the image border still has a
    boundary there.
    r   )r%   r&   r   r   )r#   r+   s     r!   r   r   O   sC   € õ �'�4Ñ Ô ð 9ÝÔ ¨Ñ8Ô8Ð8ÝÔ˜W˜I ~Ñ6Ô6°qÔ9Ð9r"   )r   r   r   r   )r#   r   r   r   )r#   r   r   r   )r*   )r#   r   r+   r,   r   r   )Ú__doc__Ú
__future__r   Útypingr   ÚnumpyÚnpÚ r   r   Ú__all__r   r	   r   r   r   r   r   r   r
   r   r   © r"   r!   ú<module>r6      s
  ðð
ð 
ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à Ð Ð Ð à Ð Ð Ð Ð Ð ðð ð €ð „i€ØŒ€ØÔ€Ø	Œ€Ø	Œ€ØÔ+Ð ðBð Bð Bð Bð,ð ,ð ,ð ,ð$ð $ð $ð $ð&ð &ð &ð &ð
:ð 
:ð 
:ð 
:ð 
:ð 
:ð 
:r"   