
    3j
                     `    S SK r S SKJs  Jr  SS\ R
                  S\S\ R
                  4S jjrg)    Nimagenum_iterationsreturnc                    [        U [        R                  5      (       d  [        S[	        U 5       35      e[        U[
        5      (       a  US:  a  [        S5      e[        U R                  5      S:  d  U R                  S   S:w  a  [        SU R                   35      eU R                  SS u  p#U R                  S	SX#5      nUS:H  nUR                  u  n    n[        R                  " SXb-  U-  S-   U R                  U R                  S
9R                  S	SX#45      nSX) '   [        U5       H0  n[        R                  " USSSS9n[        R                   " X5      nM2     UR#                  U 5      $ )aj  Compute the Connected-component labelling (CCL) algorithm.

.. image:: https://github.com/kornia/data/raw/main/cells_segmented.png

The implementation is an adaptation of the following repository:

https://gist.github.com/efirdc/5d8bd66859e574c683a504a4690ae8bc

.. warning::
    This is an experimental API subject to changes and optimization improvements.

.. note::
   See a working example `here <https://kornia.github.io/tutorials/nbs/connected_components.html>`__.

Args:
    image: the binarized input image with shape :math:`(*, 1, H, W)`.
      The image must be in floating point with range [0, 1].
    num_iterations: the number of iterations to make the algorithm to converge.

Return:
    The labels image with the same shape of the input image.

Example:
    >>> img = torch.rand(2, 1, 4, 5)
    >>> img_labels = connected_components(img, num_iterations=100)

z,Input imagetype is not a torch.Tensor. Got:    z0Input num_iterations must be a positive integer.   z*Input image shape must be (*,1,H,W). Got: N)devicedtyper   )kernel_sizestridepadding)
isinstancetorchTensor	TypeErrortypeintlenshape
ValueErrorviewaranger   r   rangeF
max_pool2dmulview_as)	r   r   HW
image_viewmaskB_outs	            ]/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/contrib/connected_components.pyconnected_componentsr)      sM   8 eU\\**FtE{mTUUnc**nq.@JKK
5;;!u{{2!3Eekk]STT;;rsDAB1(J ?D !!JAq!Q
,,q!%!)a-EKK
P
U
UWY[\^_Vc
dCCJ>"ll3AaCii" # ;;u    )d   )r   torch.nn.functionalnn
functionalr   r   r   r)    r*   r(   <module>r0      s2   $   4 4c 4ELL 4r*   