
    9i                     $   S SK r S SKrS SKJr  S SKJr  S SKrSSKJ	r	  S SK
Jr  SSKJr  0 r\R                  " \ R                   R#                  \ R                   R%                  \5      S5      5      \S'   \R                  " \ R                   R#                  \ R                   R%                  \5      S	5      5      \S
'   S rS)S jrS r\R.                  SS.S jr\" SSSS9\R.                  4SS.S jj5       rS*S jr\" SSSS9\R.                  4SS.S jj5       r\R.                  4SS.S jjr\R.                  4S jrS\R.                  4S jr\R.                  4SSS.S jjr\R.                  4S jr \R.                  4S jr!\R.                  4SS.S  jjr"\" SSSS9\R.                  4SS.S! jj5       r#\R.                  4SS.S" jjr$\R.                  4SSS.S# jjr%\R.                  4SS.S$ jjr&\R.                  4S% jr'S& r(SS'.S( jr)g)+    N)Sequence)Integral   )draw)
morphology)deprecate_funczdisk_decompositions.npyzball_decompositions.npy   c                    ^ [        U S5      (       a  gS m[        U [        5      (       a'  [        U4S jU  5       5      (       d  [	        S5      e g[	        S5      e)N__array_interface__Fc                     [        U [        5      =(       a>    [        U 5      S:H  =(       a)    [        U S   S5      =(       a    [        U S   [        5      $ )Nr   r   r      )
isinstancer   lenhasattrr   )ts    ]/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/morphology/footprints.py_validate_sequence_element:_footprint_is_sequence.<locals>._validate_sequence_element    sJ    q(# +A!+!34+ 1Q4*		
    c              3   4   >#    U  H  nT" U5      v   M     g 7fN ).0r   r   s     r   	<genexpr>)_footprint_is_sequence.<locals>.<genexpr>)   s     D)Q-a00)s   zAll elements of footprint sequence must be a 2-tuple where the first element of the tuple is an ndarray and the second is an integer indicating the number of iterations.z/footprint must be either an ndarray or SequenceT)r   r   r   all
ValueError)	footprintr   s    @r   _footprint_is_sequencer      se    y/00
 )X&&D)DDDE  E  JKKr   c                    [        U 5      (       d  [        S5      eU S   S   R                  nS/U-  nS n[        U5       H  nU S   u  pgU" UR                  U   U5        UR                  U   US-
  UR                  U   S-
  -  -   X5'   U SS  H9  u  pgU" UR                  U   U5        X5==   XvR                  U   S-
  -  -  ss'   M;     M     [        U5      $ )zDetermine the shape of composite footprint

In the future if we only want to support odd-sized square, we may want to
change this to require_odd_size
z!expected a sequence of footprintsr   c                 <    U(       a  U S-  S:X  a  [        S5      eg g )Nr   r   z0expected all footprint elements to have odd sizer   )sizerequire_odd_sizes     r   	_odd_size'_shape_from_sequence.<locals>._odd_size?   s#    qAOPP !.r   r   N)r   r   ndimrangeshapetuple)
footprintsr$   r'   r)   r%   dfpnrepss           r   _shape_from_sequencer/   4   s     "*--<==a=  DC$JEQ 4[qM	"((1+/088A;%!)a!@@#ABIBbhhqk#34H!q11H (	  <r   c                     [        U 5      n[        R                  " U[        S9nSU[	        S U 5       5      '   [
        R                  " X 5      $ )a  Convert a footprint sequence into an equivalent ndarray.

Parameters
----------
footprints : tuple of 2-tuples
    A sequence of footprint tuples where the first element of each tuple
    is an array corresponding to a footprint and the second element is the
    number of times it is to be applied. Currently, all footprints should
    have odd size.

Returns
-------
footprint : ndarray
    An single array equivalent to applying the sequence of ``footprints``.
dtyper   c              3   *   #    U  H	  oS -  v   M     g7f)r   Nr   )r   ss     r   r   *footprint_from_sequence.<locals>.<genexpr>a   s     %u!Avus   )r/   npzerosboolr*   r   binary_dilation)r+   r)   imags      r   footprint_from_sequencer;   M   sD    $ !,E88E&D)*D%u%	%&%%d77r   r2   decompositionc                0  ^ ^^ [        S T  5       5      nUS:X  a  U(       a  [        R                  " SSS9  SnUU 4S jmUc  [        R                  " T TS9nU$ US	;   a   [        U4S
 j[        T 5       5       5      nU$ US:X  a  [        T 5      n[        US5      n[        R                  " S[        T 5      -  TS9U4/n[        T 5       H,  u  pxX:  d  M  X-
  S-   n	T" Xy5      n
UR                  U
5        M.     [        U5      nU$ [        SU 35      e)a  Generate a rectangular or hyper-rectangular footprint.

Generates, depending on the length and dimensions requested with `shape`,
a square, rectangle, cube, cuboid, or even higher-dimensional versions
of these shapes.

Parameters
----------
shape : tuple[int, ...]
    The length of the footprint in each dimension. The length of the
    sequence determines the number of dimensions of the footprint.
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'separable', 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    give an identical result to a single, larger footprint, but often with
    better computational performance. See Notes for more details.
    With 'separable', this function uses separable 1D footprints for each
    axis. Whether 'sequence' or 'separable' is computationally faster may
    be architecture-dependent.

Returns
-------
footprint : array or tuple[tuple[ndarray, int], ...]
    A footprint consisting only of ones, i.e. every pixel belongs to the
    neighborhood. When `decomposition` is None, this is just an array.
    Otherwise, this will be a tuple whose length is equal to the number of
    unique structuring elements to apply (see Examples for more detail).

Examples
--------
>>> import skimage as ski
>>> ski.morphology.footprint_rectangle((3, 5))
array([[1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1]], dtype=uint8)

Decomposition will return multiple footprints that combine into a simple
footprint of the requested shape.

>>> ski.morphology.footprint_rectangle((9, 9), decomposition="sequence")
((array([[1, 1, 1],
         [1, 1, 1],
         [1, 1, 1]], dtype=uint8),
  4),)

`"sequence"` makes sure that the decomposition only returns 1D footprints.

>>> ski.morphology.footprint_rectangle((3, 5), decomposition="separable")
((array([[1],
         [1],
         [1]], dtype=uint8),
  1),
 (array([[1, 1, 1, 1, 1]], dtype=uint8), 1))

Generate a 5-dimensional hypercube with 3 samples in each dimension

>>> ski.morphology.footprint_rectangle((3,) * 5).shape
(3, 3, 3, 3, 3)
c              3   0   #    U  H  oS -  S:H  v   M     g7f)r   r   Nr   )r   widths     r   r   &footprint_rectangle.<locals>.<genexpr>   s     ;UEaUs   sequencezkdecomposition='sequence' is only supported for uneven footprints, falling back to decomposition='separable'r   )
stacklevelsequence_fallbackc                 r   > SU -  U4-   S[        T5      U -
  S-
  -  -   n[        R                  " UTS9S4nU$ )Nr   r   r1   )r   r6   ones)dimr@   shape_r-   r2   r)   s       r   partial_footprint.footprint_rectangle.<locals>.partial_footprint   sE    uh&Uc1AA1E)FFggfE*A.	r   r1   )	separablerD   c              3   8   >#    U  H  u  pT" X5      v   M     g 7fr   r   )r   rH   r@   rJ   s      r   r   rA      s       
<Ljcc))<Ls   r	   r	   r   Unrecognized decomposition: )anywarningswarnr6   rG   r*   	enumeratemin_decompose_sizer   appendr   )r)   r2   r=   has_even_widthr   	min_widthsq_repsrH   r@   nextra	componentrJ   s   ``         @r   footprint_rectangler\   e   s4   | ;U;;N
"~8	

 ,
 GGE/	* ' 
<	< 
<Ee<L
 
	$  
*	$J	!)Q/ggdSZ/u=wGH	#E*JC *Q.-c:	  +	 +
 )$	
  7GHHr   z0.25z0.27z5Use `skimage.morphology.footprint_rectangle` instead.)deprecated_versionremoved_versionhintr=   c                    [        X 4XS9nU$ )a  Generates a flat, square-shaped footprint.

Every pixel along the perimeter has a chessboard distance
no greater than radius (radius=floor(width/2)) pixels.

Parameters
----------
width : int
    The width and height of the square.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'separable', 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    give an identical result to a single, larger footprint, but often with
    better computational performance. See Notes for more details.
    With 'separable', this function uses separable 1D footprints for each
    axis. Whether 'sequence' or 'separable' is computationally faster may
    be architecture-dependent.

Returns
-------
footprint : ndarray or tuple
    The footprint where elements of the neighborhood are 1 and 0 otherwise.
    When `decomposition` is None, this is just a numpy.ndarray. Otherwise,
    this will be a tuple whose length is equal to the number of unique
    structuring elements to apply (see Notes for more detail)

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

For binary morphology, using ``decomposition='sequence'`` or
``decomposition='separable'`` were observed to give better performance than
``decomposition=None``, with the magnitude of the performance increase
rapidly increasing with footprint size. For grayscale morphology with
square footprints, it is recommended to use ``decomposition=None`` since
the internal SciPy functions that are called already have a fast
implementation based on separable 1D sliding windows.

The 'sequence' decomposition mode only supports odd valued `width`. If
`width` is even, the sequence used will be identical to the 'separable'
mode.
r)   r2   r=   r\   r@   r2   r=   r   s       r   squarere      s    n $nEI r   c                 D    US-  S:w  a  [        S5      eSX-
  US-
  -  -   $ )zDetermine number of repeated iterations for a `kernel_size` kernel.

Returns how many repeated morphology operations with an element of size
`kernel_size` is equivalent to a morphology with a single kernel of size
`n`.

r   r   z(only odd length kernel_size is supportedr"   )r#   kernel_sizes     r   rU   rU     s3     Q!CDD"a888r   c                    [        X4X#S9nU$ )a  Generates a flat, rectangular-shaped footprint.

Every pixel in the rectangle generated for a given width and given height
belongs to the neighborhood.

Parameters
----------
nrows : int
    The number of rows of the rectangle.
ncols : int
    The number of columns of the rectangle.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'separable', 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given an identical result to a single, larger footprint, but often with
    better computational performance. See Notes for more details.
    With 'separable', this function uses separable 1D footprints for each
    axis. Whether 'sequence' or 'separable' is computationally faster may
    be architecture-dependent.

Returns
-------
footprint : ndarray or tuple
    A footprint consisting only of ones, i.e. every pixel belongs to the
    neighborhood. When `decomposition` is None, this is just a
    numpy.ndarray. Otherwise, this will be a tuple whose length is equal to
    the number of unique structuring elements to apply (see Notes for more
    detail)

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

For binary morphology, using ``decomposition='sequence'``
was observed to give better performance, with the magnitude of the
performance increase rapidly increasing with footprint size. For grayscale
morphology with rectangular footprints, it is recommended to use
``decomposition=None`` since the internal SciPy functions that are called
already have a fast implementation based on separable 1D sliding windows.

The `sequence` decomposition mode only supports odd valued `nrows` and
`ncols`. If either `nrows` or `ncols` is even, the sequence used will be
identical to ``decomposition='separable'``.

- The use of ``width`` and ``height`` has been deprecated in
  version 0.18.0. Use ``nrows`` and ``ncols`` instead.
rb   rc   )nrowsncolsr2   r=   r   s        r   	rectanglerk     s    x $nEI r   c                   Uc~  [         R                  " SU S-  S-   5      n[         R                  " X35      u  pE[         R                  " [         R                  " X@-
  5      [         R                  " XP-
  5      -   U :*  US9nU$ US:X  a0  [        SUSS9n[        SU -  S-   UR                  S   5      nXx44nU$ [        SU 35      e)	a  Generates a flat, diamond-shaped footprint.

A pixel is part of the neighborhood (i.e. labeled 1) if
the city block/Manhattan distance between it and the center of
the neighborhood is no greater than radius.

Parameters
----------
radius : int
    The radius of the diamond-shaped footprint.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given an identical result to a single, larger footprint, but with
    better computational performance. See Notes for more details.

Returns
-------
footprint : ndarray or tuple
    The footprint where elements of the neighborhood are 1 and 0 otherwise.
    When `decomposition` is None, this is just a numpy.ndarray. Otherwise,
    this will be a tuple whose length is equal to the number of unique
    structuring elements to apply (see Notes for more detail)

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

For either binary or grayscale morphology, using
``decomposition='sequence'`` was observed to have a performance benefit,
with the magnitude of the benefit increasing with increasing footprint
size.

Nr   r   r   r1   rB   r<   rO   )	r6   arangemeshgridarrayabsdiamondrU   r)   r   )	radiusr2   r=   LIJr   r-   r.   s	            r   rq   rq   V  s    T IIa!a({{1 HHFF1:
!33v=U
	  
*	$Qe48F
Q<[N	  7GHHr   c                    U S:X  a3  [        USSS9nUS:X  a  [        S0 UD6S44$ US:X  a  [        S0 UD6S44$ U[        ;  a  [	        S5      e[        U   nUR
                  S   nX:  a  [	        S	U S
U 35      eX@   u  pgn/ n	US:  a*  [        XS9n
U
 Vs/ s H  oR                  X45      PM       nUS:  au  [        R                  " SU-  US9n[        SS5      /U-  n[        U5       H,  n[        S5      X'   SU[        U5      '   [        SS5      X'   M.     U	R                  X45        US:  a*  [        R                  " SU-  US9nU	R                  X45        [        U	5      $ s  snf )aB  Generate a sequence of footprints approximating an n-sphere.

Morphological operations with an n-sphere (hypersphere) footprint can be
approximated by applying a series of smaller footprints of extent 3 along
each axis. Specific solutions for this are given in [1]_ for the case of
2D disks with radius 2 through 10.

Here we used n-dimensional extensions of the "square", "diamond" and
"t-shaped" elements from that publication. All of these elementary elements
have size ``(3,) * ndim``. We numerically computed the number of
repetitions of each element that gives the closest match to the disk
(in 2D) or ball (in 3D) computed with ``decomposition=None``.

The approach can be extended to higher dimensions, but we have only stored
results for 2D and 3D at this point.

Empirically, the shapes at large radius approach a hexadecagon
(16-sides [2]_) in 2D and a rhombicuboctahedron (26-faces, [3]_) in 3D.

References
----------
.. [1] Park, H and Chin R.T. Decomposition of structuring elements for
       optimal implementation of morphological operations. In Proceedings:
       1997 IEEE Workshop on Nonlinear Signal and Image Processing, London,
       UK.
       https://www.iwaenc.org/proceedings/1997/nsip97/pdf/scan/ns970226.pdf
.. [2] https://en.wikipedia.org/wiki/Hexadecagon
.. [3] https://en.wikipedia.org/wiki/Rhombicuboctahedron
r   FN)r2   strict_radiusr=   r   r	   zMsequence decompositions are only currently available for 2d disks or 3d ballsr   zprecomputed z)D decomposition unavailable for radius > r'   r2   rN   r1   rF   )dictdiskball_nsphere_decompositionsr   r)   _t_shaped_element_seriesrV   r6   r7   slicer(   r*   rG   )rr   r'   r2   kwargsprecomputed_decompositions
max_radiusnum_t_seriesnum_diamond
num_squarerB   all_tr   r,   slaxsqs                   r   _nsphere_series_decompositionr     s   > {EdK19&v&*,,QY&v&*,, **#
 	
 "9!>+11!4J4& !"|%
 	
 -G,N)LzHa(d@5:;U!*	+U;QHHTD[.Aqk]T!+B4[BFAeBiL1a[BF  	()A~WWTD[.()? 	<s   E,c                 .   U S:X  ag  [         R                  " / SQ/ SQ/ SQ/US9n[         R                  " US5      n[         R                  " US5      n[         R                  " US5      nX#XE4$ / n[        U 5       H  nS H  n[         R                  " SU -  US9n	[        S	5      /U -  n
[        XS-   5      X'   SU	[        U
5      '   [        SS5      /U -  n
[        S	5      X'   SU	[        U
5      '   UR                  U	5        M     M     [        U5      $ )
a  A series of T-shaped structuring elements.

In the 2D case this is a T-shaped element and its rotation at multiples of
90 degrees. This series is used in efficient decompositions of disks of
various radius as published in [1]_.

The generalization to the n-dimensional case can be performed by having the
"top" of the T to extend in (ndim - 1) dimensions and then producing a
series of rotations such that the bottom end of the T points along each of
``2 * ndim`` orthogonal directions.
r   )r   r   r   )r   r   r   r1   r   r	   )r   r   rN   N)r6   ro   rot90r(   r7   r~   r*   rV   )r'   r2   t0t90t180t270r   r   idxr   r   s              r   r}   r}     s     qy XXy)Y7uEhhr1oxxAxxA"" +BHHTD[6Dk]T)s!G, %)Aqk]T)t %)Q   <r   Trw   r=   c                0   Ucc  [         R                  " U * U S-   5      n[         R                  " XD5      u  pVU(       d  U S-  n [         R                  " US-  US-  -   U S-  :*  US9$ US:X  a  [	        U SUS9nU$ US:X  a  [        XUSS	9n[        U5      nW$ )
u   Generates a flat, disk-shaped footprint.

A pixel is within the neighborhood if the Euclidean distance between
it and the origin is no greater than radius (This is only approximately
True, when `decomposition == 'sequence'`).

Parameters
----------
radius : int
    The radius of the disk-shaped footprint.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
strict_radius : bool, optional
    If False, extend the radius by 0.5. This allows the circle to expand
    further within a cube that remains of size ``2 * radius + 1`` along
    each axis. This parameter is ignored if decomposition is not None.
decomposition : {None, 'sequence', 'crosses'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given a result equivalent to a single, larger footprint, but with
    better computational performance. For disk footprints, the 'sequence'
    or 'crosses' decompositions are not always exactly equivalent to
    ``decomposition=None``. See Notes for more details.

Returns
-------
footprint : ndarray
    The footprint where elements of the neighborhood are 1 and 0 otherwise.

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

The disk produced by the ``decomposition='sequence'`` mode may not be
identical to that with ``decomposition=None``. A disk footprint can be
approximated by applying a series of smaller footprints of extent 3 along
each axis. Specific solutions for this are given in [1]_ for the case of
2D disks with radius 2 through 10. Here, we numerically computed the number
of repetitions of each element that gives the closest match to the disk
computed with kwargs ``strict_radius=False, decomposition=None``.

Empirically, the series decomposition at large radius approaches a
hexadecagon (a 16-sided polygon [2]_). In [3]_, the authors demonstrate
that a hexadecagon is the closest approximation to a disk that can be
achieved for decomposition with footprints of shape (3, 3).

The disk produced by the ``decomposition='crosses'`` is often but not
always  identical to that with ``decomposition=None``. It tends to give a
closer approximation than ``decomposition='sequence'``, at a performance
that is fairly comparable. The individual cross-shaped elements are not
limited to extent (3, 3) in size. Unlike the 'seqeuence' decomposition, the
'crosses' decomposition can also accurately approximate the shape of disks
with ``strict_radius=True``. The method is based on an adaption of
algorithm 1 given in [4]_.

References
----------
.. [1] Park, H and Chin R.T. Decomposition of structuring elements for
       optimal implementation of morphological operations. In Proceedings:
       1997 IEEE Workshop on Nonlinear Signal and Image Processing, London,
       UK.
       https://www.iwaenc.org/proceedings/1997/nsip97/pdf/scan/ns970226.pdf
.. [2] https://en.wikipedia.org/wiki/Hexadecagon
.. [3] Vanrell, M and Vitrià, J. Optimal 3 × 3 decomposable disks for
       morphological transformations. Image and Vision Computing, Vol. 15,
       Issue 11, 1997.
       :DOI:`10.1016/S0262-8856(97)00026-7`
.. [4] Li, D. and Ritter, G.X. Decomposition of Separable and Symmetric
       Convex Templates. Proc. SPIE 1350, Image Algebra and Morphological
       Image Processing, (1 November 1990).
       :DOI:`10.1117/12.23608`
Nr         ?r   r1   rB   rx   crossesr   )r6   rm   rn   ro   r   rz   _cross_decomposition)	rr   r2   rw   r=   rs   XYrB   r-   s	            r   rz   rz     s    \ IIvgvz*{{1 cMFxxA12%@@	*	$0auM O 
)	#&}DQ'+Or   c                     [        SU -  S-   5      n[        SU-  S-   5      n[        R                  " X44US9nUS:w  a  SXPSS24'   U S:w  a	  SUSS2U4'   U$ )z_Cross-shaped structuring element of shape (r0, r1).

Only the central row and column are ones.
r   r   r1   r   N)intr6   r7   )r0r1r2   s0s1cs         r   _crossr   X  sc    
 
QVaZB	QVaZB
"'A	Qwa%	Qw!R%Hr   c                    X R                   S   S-  S2U R                   S   S-  S24   nUR                  S[        S9n[        R                  " U[        R
                  " S/[        S945      nSn0 nSn[        UR                  S-
  5       HF  nX7   X7S-      :  d  M  US:X  a  M  X4   X7   -
  Xt-
  4nXhS   -  nX;  a  SXX'   OXX==   S-  ss'   UnMH     UR                   S   S-
  U-
  n	U	S:  a  U	S4nUR                  US5      S-   XX'   [        UR                  5        V
VV	s/ s H  u  u  pn	[        XU5      U	4PM     sn	nn
5      $ s  sn	nn
f )a'  Decompose a symmetric convex footprint into cross-shaped elements.

This is a decomposition of the footprint into a sequence of
(possibly asymmetric) cross-shaped elements. This technique was proposed in
[1]_ and corresponds roughly to algorithm 1 of that publication (some
details had to be modified to get reliable operation).

.. [1] Li, D. and Ritter, G.X. Decomposition of Separable and Symmetric
       Convex Templates. Proc. SPIE 1350, Image Algebra and Morphological
       Image Processing, (1 November 1990).
       :DOI:`10.1117/12.23608`
r   r   Nr   r1   )r)   sumr   r6   concatenateasarrayr(   r#   getr*   itemsr   )r   r2   quadrantcol_sumsi_prevr   sum0ikeynr   r   s               r   r   r   g  sX    +q02IOOA4F!4K4MMNH||AS|)H~~xQCs)CDEHF
CD8==1$%;a%(Av#hk11:>CFND~AF & 	qA$A1u!f773?Q&		L"16"%(!,LMMLs   &Ec                    UcK  [         R                  " SU-  S-   SU -  S-   4US9n[        R                  " XUS-   U S-   5      u  pVSXEU4'   U$ US:X  a  [        XUSS9n[	        U5      nW$ )a  Generates a flat, ellipse-shaped footprint.

Every pixel along the perimeter of ellipse satisfies
the equation ``(x/width+1)**2 + (y/height+1)**2 = 1``.

Parameters
----------
width : int
    The width of the ellipse-shaped footprint.
height : int
    The height of the ellipse-shaped footprint.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'crosses'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given an identical result to a single, larger footprint, but with
    better computational performance. See Notes for more details.

Returns
-------
footprint : ndarray
    The footprint where elements of the neighborhood are 1 and 0 otherwise.
    The footprint will have shape ``(2 * height + 1, 2 * width + 1)``.

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

The ellipse produced by the ``decomposition='crosses'`` is often but not
always  identical to that with ``decomposition=None``. The method is based
on an adaption of algorithm 1 given in [1]_.

References
----------
.. [1] Li, D. and Ritter, G.X. Decomposition of Separable and Symmetric
       Convex Templates. Proc. SPIE 1350, Image Algebra and Morphological
       Image Processing, (1 November 1990).
       :DOI:`10.1117/12.23608`

Examples
--------
>>> from skimage.morphology import footprints
>>> footprints.ellipse(5, 3)
array([[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0]], dtype=uint8)

Nr   r   r1   r   r`   )r6   r7   r   ellipser   )	r@   heightr2   r=   r   rowscolsr-   rB   s	            r   r   r     s    v HHa&j1na%i!m<EJ	\\&!UQYG
 !	*	)	#UE>'+Or   c                    [        X U 4XS9nU$ )a!  Generates a cube-shaped footprint.

This is the 3D equivalent of a square.
Every pixel along the perimeter has a chessboard distance
no greater than radius (radius=floor(width/2)) pixels.

Parameters
----------
width : int
    The width, height and depth of the cube.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'separable', 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given an identical result to a single, larger footprint, but often with
    better computational performance. See Notes for more details.

Returns
-------
footprint : ndarray or tuple
    The footprint where elements of the neighborhood are 1 and 0 otherwise.
    When `decomposition` is None, this is just a numpy.ndarray. Otherwise,
    this will be a tuple whose length is equal to the number of unique
    structuring elements to apply (see Notes for more detail)

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

For binary morphology, using ``decomposition='sequence'``
was observed to give better performance, with the magnitude of the
performance increase rapidly increasing with footprint size. For grayscale
morphology with square footprints, it is recommended to use
``decomposition=None`` since the internal SciPy functions that are called
already have a fast implementation based on separable 1D sliding windows.

The 'sequence' decomposition mode only supports odd valued `width`. If
`width` is even, the sequence used will be identical to the 'separable'
mode.
rb   rc   rd   s       r   cuber     s!    h $U#5I r   c                   Uc  SU -  S-   n[         R                  U * XS-  2U * XS-  2U * XS-  24   u  pEn[         R                  " U5      [         R                  " U5      -   [         R                  " U5      -   n[         R                  " Xp:*  US9nU$ US:X  a0  [	        SUSS9n	[        SU -  S-   U	R                  S   5      n
X44nU$ [        S	U 35      e)
a  Generates a octahedron-shaped footprint.

This is the 3D equivalent of a diamond.
A pixel is part of the neighborhood (i.e. labeled 1) if
the city block/Manhattan distance between it and the center of
the neighborhood is no greater than radius.

Parameters
----------
radius : int
    The radius of the octahedron-shaped footprint.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given an identical result to a single, larger footprint, but with
    better computational performance. See Notes for more details.

Returns
-------
footprint : ndarray or tuple
    The footprint where elements of the neighborhood are 1 and 0 otherwise.
    When `decomposition` is None, this is just a numpy.ndarray. Otherwise,
    this will be a tuple whose length is equal to the number of unique
    structuring elements to apply (see Notes for more detail)

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

For either binary or grayscale morphology, using
``decomposition='sequence'`` was observed to have a performance benefit,
with the magnitude of the benefit increasing with increasing footprint
size.
Nr   r                 ?r1   rB   r<   r   rO   )r6   mgridrp   ro   
octahedronrU   r)   r   )rr   r2   r=   r   Zr   r   r4   r   r-   r.   s              r   r   r     s    V JN((Gf2v%Gf2v%Gf2v%'
a
 FF1Iq	!BFF1I-HHQ[6	  
*	$d;F
Q<[N	  7GHHr   c                   Ucj  SU -  S-   n[         R                  U * XS-  2U * XS-  2U * XS-  24   u  pVnUS-  US-  -   US-  -   nU(       d  U S-  n [         R                  " XU -  :*  US9$ US:X  a  [        U SUS9n	U	$ [	        S	U 35      e)
a  Generates a ball-shaped footprint.

This is the 3D equivalent of a disk.
A pixel is within the neighborhood if the Euclidean distance between
it and the origin is no greater than radius.

Parameters
----------
radius : float
    The radius of the ball-shaped footprint.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
strict_radius : bool, optional
    If False, extend the radius by 0.5. This allows the circle to expand
    further within a cube that remains of size ``2 * radius + 1`` along
    each axis. This parameter is ignored if decomposition is not None.
decomposition : {None, 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given a result equivalent to a single, larger footprint, but with
    better computational performance. For ball footprints, the sequence
    decomposition is not exactly equivalent to decomposition=None.
    See Notes for more details.

Returns
-------
footprint : ndarray or tuple
    The footprint where elements of the neighborhood are 1 and 0 otherwise.

Notes
-----
The disk produced by the decomposition='sequence' mode is not identical
to that with decomposition=None. Here we extend the approach taken in [1]_
for disks to the 3D case, using 3-dimensional extensions of the "square",
"diamond" and "t-shaped" elements from that publication. All of these
elementary elements have size ``(3,) * ndim``. We numerically computed the
number of repetitions of each element that gives the closest match to the
ball computed with kwargs ``strict_radius=False, decomposition=None``.

Empirically, the equivalent composite footprint to the sequence
decomposition approaches a rhombicuboctahedron (26-faces [2]_).

References
----------
.. [1] Park, H and Chin R.T. Decomposition of structuring elements for
       optimal implementation of morphological operations. In Proceedings:
       1997 IEEE Workshop on Nonlinear Signal and Image Processing, London,
       UK.
       https://www.iwaenc.org/proceedings/1997/nsip97/pdf/scan/ns970226.pdf
.. [2] https://en.wikipedia.org/wiki/Rhombicuboctahedron
r   r   r   r   r1   rB   r	   rx   rO   )r6   r   ro   r   r   )
rr   r2   rw   r=   r   r   r   r   r4   rB   s
             r   r{   r{   I  s    n JN((Gf2v%Gf2v%Gf2v%'
a
 qD1a4K!Q$cMFxxf_,E::	*	$0auM O 7GHHr   c          	      T   Xs=:X  a  S:X  a  O  O[        S5      eUc  SSKJn  [        R                  " U SU-  -   U SU-  -   45      nSUSU4'   SXQS4'   SUSX-   S-
  4'   SXPU-   S-
  S4'   SUSU4'   SXQS4'   SUSX-   S-
  4'   SXPU-   S-
  S4'   U" U5      R                  U5      nU$ US:X  ak  U S::  a  US::  a  [        XUSS	9S44$ U S:X  a  Sn US-  n/ nU S:  a  U[        [        X 4USS	95      -  nUS:  a  U[        SUSS	9U4/-  n[        U5      nU$ [        S
U 35      e)a  Generates an octagon shaped footprint.

For a given size of (m) horizontal and vertical sides
and a given (n) height or width of slanted sides octagon is generated.
The slanted sides are 45 or 135 degrees to the horizontal axis
and hence the widths and heights are equal. The overall size of the
footprint along a single axis will be ``m + 2 * n``.

Parameters
----------
m : int
    The size of the horizontal and vertical sides.
n : int
    The height or width of the slanted sides.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.
decomposition : {None, 'sequence'}, optional
    If None, a single array is returned. For 'sequence', a tuple of smaller
    footprints is returned. Applying this series of smaller footprints will
    given an identical result to a single, larger footprint, but with
    better computational performance. See Notes for more details.

Returns
-------
footprint : ndarray or tuple
    The footprint where elements of the neighborhood are 1 and 0 otherwise.
    When `decomposition` is None, this is just a numpy.ndarray. Otherwise,
    this will be a tuple whose length is equal to the number of unique
    structuring elements to apply (see Notes for more detail)

Notes
-----
When `decomposition` is not None, each element of the `footprint`
tuple is a 2-tuple of the form ``(ndarray, num_iter)`` that specifies a
footprint array and the number of iterations it is to be applied.

For either binary or grayscale morphology, using
``decomposition='sequence'`` was observed to have a performance benefit,
with the magnitude of the benefit increasing with increasing footprint
size.
r   zm and n cannot both be zeroNr   convex_hull_imager   rB   r<   rO   )r    r   r6   r7   astypeoctagonlistr\   rq   r*   )mr   r2   r=   r   r   rB   s          r   r   r     s   Z 	{{677 'HHa!a%iQU34		!Q$	Q$"#	!QUQY,"#	a%!)Q,	"a%	R%#$	"aeai- #$	a%!)R- %i077>	( ' 
*	$6a1fQdCQGII 6AFAq5#QF%zR H q5'!5EqIJJH(O	  7GHHr   c                    SSK Jn  U S:X  a  [        R                  " SU5      nSUSS& U$ SU -  S-   nU S-  n[        R                  " USU-  -   USU-  -   45      nSXeXE-   2XTU-   24'   USU-  -   S-
  S-  n[        R                  " USU-  -   USU-  -   45      nS=USU4'   USU4'   S=XS4'   XS4'   U" U5      R	                  [
        5      nXh-   n	SXS:  '   U	R	                  U5      $ )aH  Generates a star shaped footprint.

Start has 8 vertices and is an overlap of square of size `2*a + 1`
with its 45 degree rotated version.
The slanted sides are 45 or 135 degrees to the horizontal axis.

Parameters
----------
a : int
    Parameter deciding the size of the star structural element. The side
    of the square array returned is `2*a + 1 + 2*floor(a / 2)`.

Other Parameters
----------------
dtype : data-type, optional
    The data type of the footprint.

Returns
-------
footprint : ndarray
    The footprint where elements of the neighborhood are 1 and 0 otherwise.

r   r   )r	   r	   Nr   r   r   )r   r   r6   r7   r   r   )
ar2   r   bfilterr   r   footprint_squarer   footprint_rotatedr   s
             r   starr     s.   0 $Av((65)
	A	A	QAxxQUAAI 67-.YE	)*	
QUQ1A!a!e)QQY!789::ad/A69::d/26)*;<CCCH 4I I!mE""r   c                     [        U 5      (       a  [        S U  5       5      $ [        R                  " U 5      n U [	        SSS5      4U R
                  -     $ )a  Mirror each dimension in the footprint.

Parameters
----------
footprint : ndarray or tuple
    The input footprint or sequence of footprints

Returns
-------
inverted : ndarray or tuple
    The footprint, mirrored along each dimension.

Examples
--------
>>> footprint = np.array([[0, 0, 0],
...                       [0, 1, 1],
...                       [0, 1, 1]], np.uint8)
>>> mirror_footprint(footprint)
array([[1, 1, 0],
       [1, 1, 0],
       [0, 0, 0]], dtype=uint8)

c              3   @   #    U  H  u  p[        U5      U4v   M     g 7fr   )mirror_footprint)r   r-   r   s      r   r   #mirror_footprint.<locals>.<genexpr>0  s     FI52&r*A.Is   Nr   )r   r*   r6   r   r~   r'   )r   s    r   r   r     sN    0 i((FIFFF

9%IeD$+-	>??r   pad_endc                  ^ [        U 5      (       a  [        U4S jU  5       5      $ [        R                  " U 5      n / nU R                   H(  nUR                  US-  S:X  a  T(       a  SOSOS5        M*     [        R                  " X5      $ )at  Pad the footprint to an odd size along each dimension.

Parameters
----------
footprint : ndarray or tuple
    The input footprint or sequence of footprints
pad_end : bool, optional
    If ``True``, pads at the end of each dimension (right side), otherwise
    pads on the front (left side).

Returns
-------
padded : ndarray or tuple
    The footprint, padded to an odd size along each dimension.

Examples
--------
>>> footprint = np.array([[0, 0],
...                       [1, 1],
...                       [1, 1]], np.uint8)
>>> pad_footprint(footprint)
array([[0, 0, 0],
       [1, 1, 0],
       [1, 1, 0]], dtype=uint8)

c              3   @   >#    U  H  u  p[        UTS 9U4v   M     g7f)r   N)pad_footprint)r   r-   r   r   s      r   r    pad_footprint.<locals>.<genexpr>Q  s     T)mB8!<)s   r   r   )r   r   )r   r   )r   r   )r   r*   r6   r   r)   rV   pad)r   r   paddingszs    `  r   r   r   5  sm    6 i((T)TTT

9%IGoo"q&A+'v6R 66)%%r   )FrN   )*osrQ   collections.abcr   numbersr   numpyr6   r   r   skimager   _shared.utilsr   r|   loadpathjoindirname__file__r   r/   r;   uint8r\   re   rU   rk   rq   r   r}   rz   r   r   r   r   r   r{   r   r   r   r   r   r   r   <module>r      s<   	  $     *  WWGGLL*,EF    WWGGLL*,EF  
0280 )+ bJ 	@
  54 5
5p
9 	@
 #%(( :T :
:z (( 6T 6r 79hh FR #$288 !H xx Y$d Yx   +-(( "NJ "$ CD CL 	@
 hh 2 2
2j  XX : :z xx F$d FR  R4 Rj (( -#`@< )- !&r   