
    9iP/                         S r SSKrSSKJr  SSKJrJr  SSK	J
r
  S r\
SSS	.S
 jj5       r\
SSS	.S jj5       r\
SSS	.S jj5       r\
SSS	.S jj5       rg)z!
Binary morphological operations
    N)ndimage   )_footprint_is_sequencepad_footprint)default_footprintc           	      p    US   u  pVU " XX6US9  USS  H  u  pVU " UR                  5       UUUUS9  M     U$ )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/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/morphology/binary.py_iterate_binary_funcr      sX     Q<LBC< "!" 	HHJ%	
 & J    ignoremodec                   Uc#  [         R                  " U R                  [        S9nUS;  a  [	        SU< 35      eUS:X  a  SOSn[        USS9n[        U5      (       d  US4/n[        [        R                  U UUUS	9nU$ )
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

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 {hhu{{$/++1$:;; EM5tLi6I!),,^$	
&&!C Jr   c                   Uc#  [         R                  " U R                  [        S9nUS;  a  [	        SU< 35      eUS:X  a  SOSn[        USS9n[        U5      (       d  US4/n[        [        R                  U UUUS	9nU$ )
a  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

r   >   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 {hhu{{$/++1$:;;5=4eLi6I!),,^$	
''!C Jr   c                .    [        XUS9n[        XAX#S9nU$ )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      s"    p 
5C
#c
=CJr   c                .    [        XUS9n[        XAX#S9nU$ )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     s"    p %
6C
S
<CJr   )NN)__doc__numpyr#   scipyr   r(   
footprintsr   r   miscr   r   r)   r,   r1   r3    r   r   <module>r:      s       = #6 MH M M` MX M M` 9H 9 9x 9H 9 9r   