
    |h                     ,    d Z ddlZddlZddlZd Zd Zy)a)  Analytical transformations from raw image moments to central moments.

The expressions for the 2D central moments of order <=2 are often given in
textbooks. Expressions for higher orders and dimensions were generated in SymPy
using ``tools/precompute/moments_sympy.py`` in the GitHub repository.

    Nc                    | j                   }| j                  d   dz
  }| j                  }| j                  t        j
                  d      } t	        j                  |       }|dk\  s|dvrt        d      | }|dk(  r|d	   |d
   z  }|d   |d
   z  }|d
   |d
<   |dkD  r3|d   ||d   z  z
  |d<   |d   ||d	   z  z
  |d<   |d   ||d   z  z
  |d<   |dkD  r|d   d|z  |d   z  z
  ||d   z  z
  |dz  |d   z  z   ||z  |d	   z  z   |d<   |d   d|z  |d   z  z
  ||d   z  z
  d|z  |z  |d   z  z   |d<   |d   d|z  |d   z  z
  d|dz  z  |d	   z  z   |d<   |d   d|z  |d   z  z
  d|dz  z  |d   z  z   |d<   nK|d   |d   z  }|d   |d   z  }|d   |d   z  }|d   |d<   |dkD  rl| |d   z  |d   z   |d<   | |d   z  |d   z   |d<   | |d   z  |d   z   |d<   | |d   z  |d   z   |d<   | |d   z  |d   z   |d<   | |d   z  |d   z   |d<   |dkD  rd|dz  z  |d   z  d|z  |d   z  z
  |d   z   |d<   | |d   z  d|z  ||d   z  |d   z
  z  z   |d   z   |d<   |dz  |d   z  d|z  |d   z  z
  |||d   z  |d   z
  z  z   |d    z   |d <   d|dz  z  |d   z  d|z  |d   z  z
  |d!   z   |d!<   | |d   z  d|z  ||d   z  |d   z
  z  z   |d"   z   |d"<   | |d   z  |||d   z  |d   z
  z  z   |||d   z  |d   z
  z  z   |d#   z   |d#<   | |d   z  d|z  | |d   z  |d   z   z  z
  |d$   z   |d$<   |dz  |d   z  d|z  |d   z  z
  |||d   z  |d   z
  z  z   |d%   z   |d%<   |dz  |d   z  d|z  |d   z  z
  |||d   z  |d   z
  z  z   |d&   z   |d&<   d|dz  z  |d   z  d|z  |d   z  z
  |d'   z   |d'<   |j                  |d      S )(aO  Analytical formulae for 2D and 3D central moments of order < 4.

    `moments_raw_to_central` will automatically call this function when
    ndim < 4 and order < 4.

    Parameters
    ----------
    moments_raw : ndarray
        The raw moments.

    Returns
    -------
    moments_central : ndarray
        The central moments.
    r      F)copy         z:This function only supports 2D or 3D moments of order < 4.r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r	   r   r	   )r   r	   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r	   )r   r   r   )r   r   r   )r   r	   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r	   r   r   )ndimshapedtypeastypenpfloat64
zeros_like
ValueError)	moments_rawr
   orderfloat_dtypemoments_centralmcxcyczs	            b/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/measure/_moments_analytical.py_moments_raw_to_central_fastr      s>     Da 1$E##K$$RZZe$<KmmK0OzT'UVVAqytWqwtWqw !$19$%dGb1T7l$:OD!$%dGb1T7l$:OD!$%dGb1T7l$:OD!19 $b&1T7"#qw, a%!D'/" r'AdG#	$ D! $!b&1T7**R!D'\9AFRK!D'<QQ D! %&dGa"fqw.>$>RUQtWAT$TOD!$%dGa"fqw.>$>RUQtWAT$TOD! wZ!G*$wZ!G*$wZ!G*$#$W: 19(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$19 BE	AgJ&R!G*)<<qzI G$ aj 1r6R!G*_qz-I#JJQwZW G$ A'
"b&1W:%&QwZ!G*456 G* G$ BE	AgJ&R!G*)<<qzI G$ aj 1r6R!G*_qz-I#JJQwZW G$ aj QwZ!G*456QwZ!G*456 G* G$ aj 1r6bS1W:-='
-J#KKaPWjX G$ A'
"b&1W:%&QwZ!G*456 G* G$ A'
"b&1W:%&QwZ!G*456 G* G$ BE	AgJ&R!G*)<<qzI G$ !!+E!::    c                    | j                   }| j                  d   dz
  }|dv r|dk  rt        |       S t        j                  |       }| }t        |t        t        j                  |t                       |d|z     z        }|dk(  rt        |dz         D ]  }t        |dz         D ]  }||z   |kD  rt        |dz         D ]y  }t        j                  ||      }	|	|d    ||z
  z  z  }	t        |dz         D ]A  }
t        j                  ||
      }||d    ||
z
  z  z  }|||fxx   |	|z  |||
f   z  z  cc<   C {   |S t        j                  t        |dz         f|z   D ]  }t        |      |kD  rt        j                  |D cg c]  }t        |dz          c} D ]O  }||   }t        |||      D ]+  \  }}}|t        j                  ||      z  }|| ||z
  z  z  }- ||xx   |z  cc<   Q  |S c c}w )Nr   r   r   r   )r   )r   r   )r
   r   r   r   r   tupleeyeintrangemathcomb	itertoolsproductsumzip)r   r
   r   r   r   centerspqiterm1jterm2ordersoidxsvali_ordercidxs                      r   moments_raw_to_centralr6      sM   Da 1$Ev~%!)+K88mmK0OAAeBFF4s345$+FGGqy uqy! 
	IA519% 	Iq55=q1u IA IIaOEwqzkq1u55E"1q5\ I $		!Q71:+1q5!99'1-1a41HH-II	I
	I  ##uUQY'7&9D&@B +v;%%f'Ea!e'EF 	+DD'C#&vw#= /Ctyy#..#../ F#s*#	++  (Fs   
G9
)__doc__r$   r"   numpyr   r   r6    r   r   <module>r:      s!      m;`,r   