
    0-PhP/                         d Z ddlZddlmZ ddlmZmZ ddl	m
Z
 d Ze
ddd	d
            Ze
ddd	d            Ze
ddd	d            Ze
ddd	d            ZdS )z!
Binary morphological operations
    N)ndimage   )_footprint_is_sequencepad_footprint)default_footprintc                     |d         \  }} | |||||           |dd         D ]'\  }} | |                                 ||||           (|S )zHelper to call `binary_func` for each footprint in a sequence.

    binary_func is a binary morphology function that accepts "structure",
    "output" and "iterations" keyword arguments
    (e.g. `scipy.ndimage.binary_erosion`).
    r   )	structureoutput
iterationsborder_valuer   N)copy)binary_funcimage	footprintoutr   fpnum_iters          Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/morphology/binary.py_iterate_binary_funcr      s     Q<LBKCH<    "!"" 	
 	
H 	HHJJ%	
 	
 	
 	
 	
 J    ignoremodec                   | t          j        | j        t                    }|dvrt	          d|          |dk    rdnd}t          |d          }t          |          s|d	fg}t          t          j	        | |||
          }|S )a	  Return fast binary morphological erosion of an image.

    This function returns the same result as grayscale erosion but performs
    faster for binary images.

    Morphological erosion sets a pixel at ``(i,j)`` to the minimum over all
    pixels in the neighborhood centered at ``(i,j)``. Erosion shrinks bright
    regions and enlarges dark regions.

    Parameters
    ----------
    image : ndarray
        Binary input image.
    footprint : ndarray or tuple, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use a cross-shaped footprint (connectivity=1). The footprint
        can also be provided as a sequence of smaller footprints as described
        in the notes below.
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None is
        passed, a new array will be allocated.
    mode : str, optional
        The `mode` parameter determines how the array borders are handled.
        Valid modes are: 'max', 'min', 'ignore'.
        If 'max' or 'ignore', pixels outside the image domain are assumed
        to be `True`, which causes them to not influence the result.
        Default is 'ignore'.

        .. versionadded:: 0.23
            `mode` was added in 0.23.

    Returns
    -------
    eroded : ndarray of bool or uint
        The result of the morphological erosion taking values in
        ``[False, True]``.

    Notes
    -----
    The footprint can also be a provided as a sequence of 2-tuples where the
    first element of each 2-tuple is a footprint ndarray and the second element
    is an integer describing the number of times it should be iterated. For
    example ``footprint=[(np.ones((9, 1)), 1), (np.ones((1, 9)), 1)]``
    would apply a 9x1 footprint followed by a 1x9 footprint resulting in a net
    effect that is the same as ``footprint=np.ones((9, 9))``, but with lower
    computational cost. Most of the builtin footprints such as
    :func:`skimage.morphology.disk` provide an option to automatically generate a
    footprint sequence of this type.

    For even-sized footprints, :func:`skimage.morphology.erosion` and
    this function produce an output that differs: one is shifted by one pixel
    compared to the other.

    See also
    --------
    skimage.morphology.isotropic_erosion

    Ndtype>   maxminr   unsupported mode, got r   FTpad_endr   r   r   r   r   r   )
npemptyshapebool
ValueErrorr   r   r   ndibinary_erosionr   r   r   r   r   s        r   r)   r)   '   s    x {hu{$///+++:$::;;; EMM55tLi666I!),, %^$	
&!  C Jr   c                   | t          j        | j        t                    }|dvrt	          d|          |dk    rdnd}t          |d          }t          |          s|d	fg}t          t          j	        | |||
          }|S )aX	  Return fast binary morphological dilation of an image.

    This function returns the same result as grayscale dilation but performs
    faster for binary images.

    Morphological dilation sets a pixel at ``(i,j)`` to the maximum over all
    pixels in the neighborhood centered at ``(i,j)``. Dilation enlarges bright
    regions and shrinks dark regions.

    Parameters
    ----------
    image : ndarray
        Binary input image.
    footprint : ndarray or tuple, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use a cross-shaped footprint (connectivity=1). The footprint
        can also be provided as a sequence of smaller footprints as described
        in the notes below.
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None is
        passed, a new array will be allocated.
    mode : str, optional
        The `mode` parameter determines how the array borders are handled.
        Valid modes are: 'max', 'min', 'ignore'.
        If 'min' or 'ignore', pixels outside the image domain are assumed
        to be `False`, which causes them to not influence the result.
        Default is 'ignore'.

        .. versionadded:: 0.23
            `mode` was added in 0.23.

    Returns
    -------
    dilated : ndarray of bool or uint
        The result of the morphological dilation with values in
        ``[False, True]``.

    Notes
    -----
    The footprint can also be a provided as a sequence of 2-tuples where the
    first element of each 2-tuple is a footprint ndarray and the second element
    is an integer describing the number of times it should be iterated. For
    example ``footprint=[(np.ones((9, 1)), 1), (np.ones((1, 9)), 1)]``
    would apply a 9x1 footprint followed by a 1x9 footprint resulting in a net
    effect that is the same as ``footprint=np.ones((9, 9))``, but with lower
    computational cost. Most of the builtin footprints such as
    :func:`skimage.morphology.disk` provide an option to automatically generate a
    footprint sequence of this type.

    For non-symmetric footprints, :func:`skimage.morphology.binary_dilation`
    and :func:`skimage.morphology.dilation` produce an output that differs:
    `binary_dilation` mirrors the footprint, whereas `dilation` does not.

    See also
    --------
    skimage.morphology.isotropic_dilation

    Nr   >   r   r   r   r   r   TFr    r   r"   )
r#   r$   r%   r&   r'   r   r   r   r(   binary_dilationr*   s        r   r,   r,   x   s    x {hu{$///+++:$::;;;5==44eLi666I!),, %^$	
'!  C Jr   c                P    t          | ||          }t          ||||          }|S )a  Return fast binary morphological opening of an image.

    This function returns the same result as grayscale opening but performs
    faster for binary images.

    The morphological opening on an image is defined as an erosion followed by
    a dilation. Opening can remove small bright spots (i.e. "salt") and connect
    small dark cracks. This tends to "open" up (dark) gaps between (bright)
    features.

    Parameters
    ----------
    image : ndarray
        Binary input image.
    footprint : ndarray or tuple, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use a cross-shaped footprint (connectivity=1). The footprint
        can also be provided as a sequence of smaller footprints as described
        in the notes below.
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None
        is passed, a new array will be allocated.
    mode : str, optional
        The `mode` parameter determines how the array borders are handled.
        Valid modes are: 'max', 'min', 'ignore'.
        If 'ignore', pixels outside the image domain are assumed to be `True`
        for the erosion and `False` for the dilation, which causes them to not
        influence the result. Default is 'ignore'.

        .. versionadded:: 0.23
            `mode` was added in 0.23.

    Returns
    -------
    opening : ndarray of bool
        The result of the morphological opening.

    Notes
    -----
    The footprint can also be a provided as a sequence of 2-tuples where the
    first element of each 2-tuple is a footprint ndarray and the second element
    is an integer describing the number of times it should be iterated. For
    example ``footprint=[(np.ones((9, 1)), 1), (np.ones((1, 9)), 1)]``
    would apply a 9x1 footprint followed by a 1x9 footprint resulting in a net
    effect that is the same as ``footprint=np.ones((9, 9))``, but with lower
    computational cost. Most of the builtin footprints such as
    :func:`skimage.morphology.disk` provide an option to automatically generate a
    footprint sequence of this type.

    See also
    --------
    skimage.morphology.isotropic_opening

    r   r   r   )r)   r,   r   r   r   r   tmps        r   binary_openingr1      s4    p 	
5
5
5C
#yc
=
=
=CJr   c                P    t          | ||          }t          ||||          }|S )a  Return fast binary morphological closing of an image.

    This function returns the same result as grayscale closing but performs
    faster for binary images.

    The morphological closing on an image is defined as a dilation followed by
    an erosion. Closing can remove small dark spots (i.e. "pepper") and connect
    small bright cracks. This tends to "close" up (dark) gaps between (bright)
    features.

    Parameters
    ----------
    image : ndarray
        Binary input image.
    footprint : ndarray or tuple, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use a cross-shaped footprint (connectivity=1). The footprint
        can also be provided as a sequence of smaller footprints as described
        in the notes below.
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None,
        is passed, a new array will be allocated.
    mode : str, optional
        The `mode` parameter determines how the array borders are handled.
        Valid modes are: 'max', 'min', 'ignore'.
        If 'ignore', pixels outside the image domain are assumed to be `True`
        for the erosion and `False` for the dilation, which causes them to not
        influence the result. Default is 'ignore'.

        .. versionadded:: 0.23
            `mode` was added in 0.23.

    Returns
    -------
    closing : ndarray of bool
        The result of the morphological closing.

    Notes
    -----
    The footprint can also be a provided as a sequence of 2-tuples where the
    first element of each 2-tuple is a footprint ndarray and the second element
    is an integer describing the number of times it should be iterated. For
    example ``footprint=[(np.ones((9, 1)), 1), (np.ones((1, 9)), 1)]``
    would apply a 9x1 footprint followed by a 1x9 footprint resulting in a net
    effect that is the same as ``footprint=np.ones((9, 9))``, but with lower
    computational cost. Most of the builtin footprints such as
    :func:`skimage.morphology.disk` provide an option to automatically generate a
    footprint sequence of this type.

    See also
    --------
    skimage.morphology.isotropic_closing

    r   r.   )r,   r)   r/   s        r   binary_closingr3     s4    p %
6
6
6C
iSt
<
<
<CJr   )NN)__doc__numpyr#   scipyr   r(   
footprintsr   r   miscr   r   r)   r,   r1   r3    r   r   <module>r:      s5                    = = = = = = = = # # # # # #  6 MH M M M M M` MX M M M M M` 9H 9 9 9 9 9x 9H 9 9 9 9 9 9 9r   