
    0-Ph                     .    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	            c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/measure/_moments_analytical.py_moments_raw_to_central_fastr      sM     Da 1$E#K$$RZe$<<KmK00OzzT''UVVVAqyytWqwtWqw !$199$%dGb1T7l$:OD!$%dGb1T7l$:OD!$%dGb1T7l$:OD!199 $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: 199(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$(*sQwZ'7!G*'DOG$199 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   |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      s   Da 1$Ev~~%!))+K888mK00OAAeBF4s333445$+FGGGqyy uqy!! 
	I 
	IA519%% 	I 	Iq55==q1u I IA IaOOEwqzkq1u55E"1q5\\ I I $	!Q71:+1q5!99'1---1a41HH----II	I  #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^             m; m; m;`, , , , ,r   