+
    Ai&H                         ^ RI t ^ RIt^RIHtHt ^RIHt ^RIH	t	 RR lt
RR ltRRR/R lltRRR/R	 lltRR
 ltR tRR/R ltRRR/R lltRRR/R lltR# )    N)_supported_float_typecheck_nD)_moments_cy)moments_raw_to_centralc                    \        V ^ VR7      # )a  Calculate all raw image moments up to a certain order.

The following properties can be calculated from raw image moments:
 * Area as: ``M[0, 0]``.
 * Centroid as: {``M[1, 0] / M[0, 0]``, ``M[0, 1] / M[0, 0]``}.

Note that raw moments are neither translation, scale, nor rotation
invariant.

Parameters
----------
coords : (N, D) double or uint8 array
    Array of N points that describe an image of D dimensionality in
    Cartesian space.
order : int, optional
    Maximum order of moments. Default is 3.

Returns
-------
M : (``order + 1``, ``order + 1``, ...) array
    Raw image moments. (D dimensions)

References
----------
.. [1] Johannes Kilian. Simple Image Analysis By Moments. Durham
       University, version 0.2, Durham, 2001.

Examples
--------
>>> coords = np.array([[row, col]
...                    for row in range(13, 17)
...                    for col in range(14, 18)], dtype=np.float64)
>>> M = moments_coords(coords)
>>> centroid = (M[1, 0] / M[0, 0], M[0, 1] / M[0, 0])
>>> centroid
(14.5, 15.5)
)order)moments_coords_central)coordsr   s   &&V/var/www/html/photoedit/myenv/lib/python3.14/site-packages/skimage/measure/_moments.pymoments_coordsr   
   s    L "&!599    c                   \        V \        4      '       d   \        P                  ! V RR7      p \	        V ^4       V P
                  ^,          p\        V P                  4      pVf   \        P                  ! V ^ \        R7      pV P                  VRR7      V,
          p \        P                  ! \        V^,           4       Uu. uF  qPV,          NK  	  upRR7      p V P                  V P
                  RV^,
          ,          ,           4      p ^p\        V4       F5  pV RV3,          p\        P                  ! V^^V,           4      pWh,          pK7  	  \        P                  ! V^ R7      p	V	# u upi )a  Calculate all central image moments up to a certain order.

The following properties can be calculated from raw image moments:
 * Area as: ``M[0, 0]``.
 * Centroid as: {``M[1, 0] / M[0, 0]``, ``M[0, 1] / M[0, 0]``}.

Note that raw moments are neither translation, scale nor rotation
invariant.

Parameters
----------
coords : (N, D) double or uint8 array
    Array of N points that describe an image of D dimensionality in
    Cartesian space. A tuple of coordinates as returned by
    ``np.nonzero`` is also accepted as input.
center : tuple of float, optional
    Coordinates of the image centroid. This will be computed if it
    is not provided.
order : int, optional
    Maximum order of moments. Default is 3.

Returns
-------
Mc : (``order + 1``, ``order + 1``, ...) array
    Central image moments. (D dimensions)

References
----------
.. [1] Johannes Kilian. Simple Image Analysis By Moments. Durham
       University, version 0.2, Durham, 2001.

Examples
--------
>>> coords = np.array([[row, col]
...                    for row in range(13, 17)
...                    for col in range(14, 18)])
>>> moments_coords_central(coords)
array([[16.,  0., 20.,  0.],
       [ 0.,  0.,  0.,  0.],
       [20.,  0., 25.,  0.],
       [ 0.,  0.,  0.,  0.]])

As seen above, for symmetric objects, odd-order moments (columns 1 and 3,
rows 1 and 3) are zero when centered on the centroid, or center of mass,
of the object (the default). If we break the symmetry by adding a new
point, this no longer holds:

>>> coords2 = np.concatenate((coords, [[17, 17]]), axis=0)
>>> np.round(moments_coords_central(coords2),
...          decimals=2)  # doctest: +NORMALIZE_WHITESPACE
array([[17.  ,  0.  , 22.12, -2.49],
       [ 0.  ,  3.53,  1.73,  7.4 ],
       [25.88,  6.02, 36.63,  8.83],
       [ 4.15, 19.17, 14.8 , 39.6 ]])

Image moments and central image moments are equivalent (by definition)
when the center is (0, 0):

>>> np.allclose(moments_coords(coords),
...             moments_coords_central(coords, (0, 0)))
True
)axis)r   dtypeFcopyNNN)   )
isinstancetuplenpstackr   shaper   r   meanfloatastyperangereshapemoveaxissum)
r
   centerr   ndim
float_typeccalcr   isolated_axisMcs
   &&&       r   r	   r	   3   s)   ~ &%   &r*VQ<<?D&v||4J~au5 ]]:E]2V;F XX%	*:;*:Qqyy*:;"EF ^^FLL44!8+<<=FDdq$w M1a$h? #  
1	BI) <s   E,spacingc               @    \        V RV P                  ,          WR7      # )u  Calculate all raw image moments up to a certain order.

The following properties can be calculated from raw image moments:
 * Area as: ``M[0, 0]``.
 * Centroid as: {``M[1, 0] / M[0, 0]``, ``M[0, 1] / M[0, 0]``}.

Note that raw moments are neither translation, scale nor rotation
invariant.

Parameters
----------
image : (N[, ...]) double or uint8 array
    Rasterized shape as image.
order : int, optional
    Maximum order of moments. Default is 3.
spacing : tuple of float, shape (ndim,)
    The pixel spacing along each axis of the image.

Returns
-------
m : (``order + 1``, ``order + 1``) array
    Raw image moments.

References
----------
.. [1] Wilhelm Burger, Mark Burge. Principles of Digital Image Processing:
       Core Algorithms. Springer-Verlag, London, 2009.
.. [2] B. Jähne. Digital Image Processing. Springer-Verlag,
       Berlin-Heidelberg, 6. edition, 2005.
.. [3] T. H. Reiss. Recognizing Planar Objects Using Invariant Image
       Features, from Lecture notes in computer science, p. 676. Springer,
       Berlin, 1993.
.. [4] https://en.wikipedia.org/wiki/Image_moment

Examples
--------
>>> image = np.zeros((20, 20), dtype=np.float64)
>>> image[13:17, 13:17] = 1
>>> M = moments(image)
>>> centroid = (M[1, 0] / M[0, 0], M[0, 1] / M[0, 0])
>>> centroid
(14.5, 14.5)
r   r)   r   )moments_centralr#   )imager   r)   s   &&$r   momentsr/      s    X 5$"35RRr   c                  Vf   \        WVR7      p\        V4      # \        V P                  4      pVf#   \        P
                  ! V P                  VR7      pV P                  VRR7      p\        \        V P                  4      4      pV P                  p	V	^,           p
\        P                  ! V^,           VR7      p\        V P                  4       F  w  r\        P                  ! WR7      W<,          ,          W,          ,
          pVR\        P                  3,          V,          p\        P                  ! VVRV V	.,           W^,           R ,           VW.VRV V
.,           W^,           R ,           RR7      pK  	  V# )	u  Calculate all central image moments up to a certain order.

The center coordinates (cr, cc) can be calculated from the raw moments as:
{``M[1, 0] / M[0, 0]``, ``M[0, 1] / M[0, 0]``}.

Note that central moments are translation invariant but not scale and
rotation invariant.

Parameters
----------
image : (N[, ...]) double or uint8 array
    Rasterized shape as image.
center : tuple of float, optional
    Coordinates of the image centroid. This will be computed if it
    is not provided.
order : int, optional
    The maximum order of moments computed.
spacing : tuple of float, shape (ndim,)
    The pixel spacing along each axis of the image.

Returns
-------
mu : (``order + 1``, ``order + 1``) array
    Central image moments.

References
----------
.. [1] Wilhelm Burger, Mark Burge. Principles of Digital Image Processing:
       Core Algorithms. Springer-Verlag, London, 2009.
.. [2] B. Jähne. Digital Image Processing. Springer-Verlag,
       Berlin-Heidelberg, 6. edition, 2005.
.. [3] T. H. Reiss. Recognizing Planar Objects Using Invariant Image
       Features, from Lecture notes in computer science, p. 676. Springer,
       Berlin, 1993.
.. [4] https://en.wikipedia.org/wiki/Image_moment

Examples
--------
>>> image = np.zeros((20, 20), dtype=np.float64)
>>> image[13:17, 13:17] = 1
>>> M = moments(image)
>>> centroid = (M[1, 0] / M[0, 0], M[0, 1] / M[0, 0])
>>> moments_central(image, centroid)
array([[16.,  0., 20.,  0.],
       [ 0.,  0.,  0.,  0.],
       [20.,  0., 25.,  0.],
       [ 0.,  0.,  0.,  0.]])
Nr+   r   Fr   r   greedy)optimize)r/   r   r   r   r   onesr#   r   listr   arange	enumerater   newaxiseinsum)r.   r"   r   r)   kwargsmoments_rawfloat_dtyper&   L	sum_labelorder_labelordersdim
dim_lengthdeltapowers_of_deltas   &&&$,           r   r-   r-      s=   b ~ e'B%k22'4K''%**K8<<%<0DU5::A

Ia-KYYuqy4F$U[[1		*87<G&+U2::.&8 yydsGyk!AAgiL0$dsG{m#aa	l2
 2 Kr   c                   \         P                  ! \         P                  ! V P                  4      V8*  4      '       d   \	        R4      hVf!   \         P
                  ! V P                  4      p\         P                  ! V 4      pV P                  4       ^ ,          p\        V4      p\        P                  ! \        V^,           4      V P                  R7       Fw  p\        V4      ^8  d   \         P                  W6&   K'  W,          V\        V4      ,          ,          V\        V4      VP                  ,          ^,           ,          ,          W6&   Ky  	  V# )u  Calculate all normalized central image moments up to a certain order.

Note that normalized central moments are translation and scale invariant
but not rotation invariant.

Parameters
----------
mu : (M[, ...], M) array
    Central image moments, where M must be greater than or equal
    to ``order``.
order : int, optional
    Maximum order of moments. Default is 3.
spacing : tuple of float, shape (ndim,)
    The pixel spacing along each axis of the image.

Returns
-------
nu : (``order + 1``[, ...], ``order + 1``) array
    Normalized central image moments.

References
----------
.. [1] Wilhelm Burger, Mark Burge. Principles of Digital Image Processing:
       Core Algorithms. Springer-Verlag, London, 2009.
.. [2] B. Jähne. Digital Image Processing. Springer-Verlag,
       Berlin-Heidelberg, 6. edition, 2005.
.. [3] T. H. Reiss. Recognizing Planar Objects Using Invariant Image
       Features, from Lecture notes in computer science, p. 676. Springer,
       Berlin, 1993.
.. [4] https://en.wikipedia.org/wiki/Image_moment

Examples
--------
>>> image = np.zeros((20, 20), dtype=np.float64)
>>> image[13:17, 13:17] = 1
>>> m = moments(image)
>>> centroid = (m[0, 1] / m[0, 0], m[1, 0] / m[0, 0])
>>> mu = moments_central(image, centroid)
>>> moments_normalized(mu)
array([[       nan,        nan, 0.078125  , 0.        ],
       [       nan, 0.        , 0.        , 0.        ],
       [0.078125  , 0.        , 0.00610352, 0.        ],
       [0.        , 0.        , 0.        , 0.        ]])
z)Shape of image moments must be >= `order`)repeat)r   anyarrayr   
ValueErrorr4   r#   
zeros_likeravelmin	itertoolsproductr   r!   nan)mur   r)   numu0scalepowerss   &&&    r   moments_normalizedrU     s    Z 
vvbhhrxx E)**DEE''"''"	r	B
((*Q-CLE##E%!)$4RWWEv;?BJ*uF';;Fbgg-12BJ	 F Ir   c                    V P                   R8X  d   \        P                  M\        P                  p\        P
                  ! V P                  VRR7      4      # )u  Calculate Hu's set of image moments (2D-only).

Note that this set of moments is proved to be translation, scale and
rotation invariant.

Parameters
----------
nu : (M, M) array
    Normalized central image moments, where M must be >= 4.

Returns
-------
nu : (7,) array
    Hu's set of image moments.

References
----------
.. [1] M. K. Hu, "Visual Pattern Recognition by Moment Invariants",
       IRE Trans. Info. Theory, vol. IT-8, pp. 179-187, 1962
.. [2] Wilhelm Burger, Mark Burge. Principles of Digital Image Processing:
       Core Algorithms. Springer-Verlag, London, 2009.
.. [3] B. Jähne. Digital Image Processing. Springer-Verlag,
       Berlin-Heidelberg, 6. edition, 2005.
.. [4] T. H. Reiss. Recognizing Planar Objects Using Invariant Image
       Features, from Lecture notes in computer science, p. 676. Springer,
       Berlin, 1993.
.. [5] https://en.wikipedia.org/wiki/Image_moment

Examples
--------
>>> image = np.zeros((20, 20), dtype=np.float64)
>>> image[13:17, 13:17] = 0.5
>>> image[10:12, 10:12] = 1
>>> mu = moments_central(image)
>>> nu = moments_normalized(mu)
>>> np.round(moments_hu(nu), 4)  # doctest: +FLOAT_CMP
array([0.7454, 0.3512, 0.104 , 0.0406, 0.0026, 0.0241, 0.    ])
float32Fr   )r   r   rW   float64r   
moments_hur   )rQ   r   s   & r   rY   rY   V  s=    N ((i/BJJRZZE!!"))E)">??r   c                   \        V RV P                  ,          ^VR7      pV\        \        P                  ! V P                  \
        R7      4      ,          VRV P                  ,          ,          ,          pV# )a  Return the (weighted) centroid of an image.

Parameters
----------
image : array
    The input image.
spacing : tuple of float, shape (ndim,)
    The pixel spacing along each axis of the image.

Returns
-------
center : tuple of float, length ``image.ndim``
    The centroid of the (nonzero) pixels in ``image``.

Examples
--------
>>> image = np.zeros((20, 20), dtype=np.float64)
>>> image[13:17, 13:17] = 0.5
>>> image[10:12, 10:12] = 1
>>> centroid(image)
array([13.16666667, 13.16666667])
)r"   r   r)   r1   r,   )r-   r#   r   r   eyeint)r.   r)   Mr"   s   &$  r   centroidr^     s[    . 	dUZZ&7q'RA	%uzz-
./
D5::
	 
 Mr   c               >   Vf   \        V ^VR7      pVRV P                  ,          ,          p\        P                  ! V P                  V P                  3VP                  R7      p\        ^\        P                  ! V P                  \        R7      ,          4      p\        P                  ! V4      pRVP                  n
        \        P                  ! W,          4      W,          ,
          V,          VR&   \        P                  ! \        V P                  4      ^4       Fz  p\        P                  ! V P                  \        R7      p^V\        V4      &   V\        V4      ,          ) V,          WG&   V\        V4      ,          ) V,          VP                   V&   K|  	  V# )u  Compute the inertia tensor of the input image.

Parameters
----------
image : array
    The input image.
mu : array, optional
    The pre-computed central moments of ``image``. The inertia tensor
    computation requires the central moments of the image. If an
    application requires both the central moments and the inertia tensor
    (for example, `skimage.measure.regionprops`), then it is more
    efficient to pre-compute them and pass them to the inertia tensor
    call.
spacing : tuple of float, shape (ndim,)
    The pixel spacing along each axis of the image.

Returns
-------
T : array, shape ``(image.ndim, image.ndim)``
    The inertia tensor of the input image. :math:`T_{i, j}` contains
    the covariance of image intensity along axes :math:`i` and :math:`j`.

References
----------
.. [1] https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
.. [2] Bernd Jähne. Spatio-Temporal Image Processing: Theory and
       Scientific Applications. (Chapter 8: Tensor Methods) Springer, 1993.
r+   r1   Tr   r,   )r-   r#   r   zerosr   r   r[   r\   diagflags	writeabler!   rM   combinationsr   r5   T)	r.   rP   r)   rR   resultcorners2ddimsmu_indexs	   &&$      r   inertia_tensorrk     s*   : 
zG
 TEJJ
CXXuzz5::.bhh?F Q

#667H
AAGG FF2< 2</36AaD&&uUZZ'8!<88EJJc2 d5?++c1U8_--3	 =
 Mr   c                   Vf   \        WVR7      p\        P                  P                  V4      p\        P                  ! V^ RVR7      p\        VRR7      # )a  Compute the eigenvalues of the inertia tensor of the image.

The inertia tensor measures covariance of the image intensity along
the image axes. (See `inertia_tensor`.) The relative magnitude of the
eigenvalues of the tensor is thus a measure of the elongation of a
(bright) object in the image.

Parameters
----------
image : array
    The input image.
mu : array, optional
    The pre-computed central moments of ``image``.
T : array, shape ``(image.ndim, image.ndim)``
    The pre-computed inertia tensor. If ``T`` is given, ``mu`` and
    ``image`` are ignored.
spacing : tuple of float, shape (ndim,)
    The pixel spacing along each axis of the image.

Returns
-------
eigvals : list of float, length ``image.ndim``
    The eigenvalues of the inertia tensor of ``image``, in descending
    order.

Notes
-----
Computing the eigenvalues requires the inertia tensor of the input image.
This is much faster if the central moments (``mu``) are provided, or,
alternatively, one can provide the inertia tensor (``T``) directly.
N)r)   )outT)reverse)rk   r   linalgeigvalshclipsorted)r.   rP   re   r)   eigvalss   &&&$ r   inertia_tensor_eigvalsrt     sM    @ 	y5g6ii  #G
 gggq$G4G'4((r   )   )Nru   )ru   N)N)NN)rM   numpyr   _shared.utilsr   r    r   _moments_analyticalr   r   r	   r/   r-   rU   rY   r^   rk   rt    r   r   <module>r{      sr      ;  7&:RdN,St ,S^LD L^;|(@Vt @5d 5p()d ()r   