
    a6d                     .    d Z ddlZddlZddlZd Zd ZdS )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        }|                     t          j        d          } t	          j        |           }|dk    s|dvrt          d          | }|dk    rT|d	         |d
         z  }|d         |d
         z  }|d
         |d
<   |dk    rE|d         ||d         z  z
  |d<   |d         ||d	         z  z
  |d<   |d         ||d         z  z
  |d<   |dk    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<   n|d         |d         z  }|d         |d         z  }|d         |d         z  }|d         |d<   |dk    r| |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k    r)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  |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'<   |                    |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	            Clib/python3.11/site-packages/skimage/measure/_moments_analytical.py_moments_raw_to_central_fastr      s0     Da 1$E#K$$RZe$<<KmK00OzzT''H
 
 	
 	AqyytWqwtWqw !$199$%dGb4j$8OD!$%dGb4j$8OD!$%dGb4j$8OD!199%&tWqtAdG|%;b4j%H')1uQtW}&579"uQtW}&EOD!%&tWqtAdG|%;b4j%H'(tBwqw&7OD!$%dGad1T7l$:Qr1uWQtW_$LOD!$%dGad1T7l$:Qr1uWQtW_$LOD! wZ!G*$wZ!G*$wZ!G*$#$W: 199(*s1W:~'
'BOG$(*s1W:~'
'BOG$(*s1W:~'
'BOG$(*s1W:~'
'BOG$(*s1W:~'
'BOG$(*s1W:~'
'BOG$199()"a%'
(:*+B$qz/):*+G*)5OG$ *,AgJ*+B$1W:'
0J*K)L*+G*)5OG$ )+Aaj(81R4'
?(J*,b7maj.H*I)J*+G*)5OG$ )*"a%'
(:*+B$qz/):*+G*)5OG$ *,AgJ*+B$1W:'
0J*K)L*+G*)5OG$ *,AgJ*,b7maj.H*I)J*,b7maj.H*I)J +,G*)5OG$ *,AgJ*+B$AgJ70K*L)M*+G*)5OG$ )+Aaj(8*+B$qz/):*,b7maj.H*I)J +,G*)5OG$ )+Aaj(8*+B$qz/):*,b7maj.H*I)J +,G*)5OG$ )*"a%'
(:*+B$qz/):*+G*)5OG$ !!+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   |k    rt          |dz             D ]}t          j
        ||          }	|	|d          ||z
  z  z  }	t          |dz             D ]I}
t          j
        ||
          }||d          ||
z
  z  z  }|||fxx         |	|z  |||
f         z  z  cc<   J|S t          j        t          |dz             f|z   D ]}t          |          |k    rt          j        d |D              D ]V}||         }t          |||          D ]*\  }}}|t          j
        ||          z  }|| ||z
  z  z  }+||xx         |z  cc<   W|S )	Nr   r   r   r   )r   )r   r   c                 2    g | ]}t          |d z             S )r   )range).0os     r   
<listcomp>z*moments_raw_to_central.<locals>.<listcomp>   s"    'E'E'Ea!e'E'E'Er   )r
   r   r   r   r   tupleeyeintr   mathcomb	itertoolsproductsumzip)r   r
   r   r   r   centerspqiterm1jterm2ordersidxsvali_ordercidxs                     r   moments_raw_to_centralr9   q   s   Da 1$Ev~~%!))+K888mK00OAAeBF4s333445$t)DEEGqyy uqy!! 
	E 
	EA519%% 	E 	Eq55==q1u E EA IaOOEwqzkq1u55E"1q5\\ E E $	!Q71:+1q5!99'1---uQq!tW1DD----EE	E  #uUQY'7'7&9D&@B + +v;;%'E'Ef'E'E'EF 	+ 	+DD'C#&vw#=#= / /Cty#...#..F###s*####	+ r   )__doc__r(   r&   numpyr   r   r9    r   r   <module>r=      s^             `; `; `;F, , , , ,r   