
    !Цi,                         S r SSKJr  SSKrSSKJr  SSKJrJ	r	  SSK
JrJrJr  / SQrSS	 jrSS
 jrSS jrS rSS jrg)zP
2D and nD Discrete Wavelet Transforms and Inverse Discrete Wavelet Transforms.
    )productN   )_have_c99_complex)dwt_axis	idwt_axis)	AxisError_modes_per_axis_wavelets_per_axis)dwt2idwt2dwtnidwtnc                 &   [        U5      n[        R                  " U 5      n [        U5      S:w  a  [	        S5      eU R
                  [        [        R                  " U5      5      :  a  [	        S5      e[        XX#5      nUS   US   US   US   44$ )ae  
2D Discrete Wavelet Transform.

Parameters
----------
data : array_like
    2D array with input data
wavelet : Wavelet object or name string, or 2-tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or 2-tuple of strings, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple of modes specifying the mode to use on each axis in
    ``axes``.
axes : 2-tuple of ints, optional
    Axes over which to compute the DWT. Repeated elements mean the DWT will
    be performed multiple times along these axes.

Returns
-------
(cA, (cH, cV, cD)) : tuple
    Approximation, horizontal detail, vertical detail and diagonal
    detail coefficients respectively.  Horizontal refers to array axis 0
    (or ``axes[0]`` for user-specified ``axes``).

Examples
--------
>>> import numpy as np
>>> import pywt
>>> data = np.ones((4,4), dtype=np.float64)
>>> coeffs = pywt.dwt2(data, 'haar')
>>> cA, (cH, cV, cD) = coeffs
>>> cA
array([[ 2.,  2.],
       [ 2.,  2.]])
>>> cV
array([[ 0.,  0.],
       [ 0.,  0.]])

   Expected 2 axesz8Input array has fewer dimensions than the specified axesaadaaddd)tuplenpasarraylen
ValueErrorndimuniquer   )datawaveletmodeaxescoefss        M/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/pywt/_multidim.pyr   r      s    R ;D::dD
4yA~*++yy3ryy''   ! 	! +E;teDk5;???    c                 ~    U u  nu  pVn[        U5      n[        U5      S:w  a  [        S5      eXEXgS.n [        XX#5      $ )a:  
2-D Inverse Discrete Wavelet Transform.

Reconstructs data from coefficient arrays.

Parameters
----------
coeffs : tuple
    (cA, (cH, cV, cD)) A tuple with approximation coefficients and three
    details coefficients 2D arrays like from ``dwt2``.  If any of these
    components are set to ``None``, it will be treated as zeros.
wavelet : Wavelet object or name string, or 2-tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or 2-tuple of strings, optional
    Signal extension mode, see :ref:`Modes <ref-modes>`. This can
    also be a tuple of modes specifying the mode to use on each axis in
    ``axes``.
axes : 2-tuple of ints, optional
    Axes over which to compute the IDWT. Repeated elements mean the IDWT
    will be performed multiple times along these axes.

Examples
--------
>>> import numpy as np
>>> import pywt
>>> data = np.array([[1,2], [3,4]], dtype=np.float64)
>>> coeffs = pywt.dwt2(data, 'haar')
>>> pywt.idwt2(coeffs, 'haar')
array([[ 1.,  2.],
       [ 3.,  4.]])

r   r   )r   r   r   r   )r   r   r   r   )coeffsr   r   r    LLHLLHHHs           r"   r   r   K   sJ    F B;D
4yA~*++5F$--r#   c                     [         R                  " U 5      n [        (       df  [         R                  " U 5      (       aK  [	        U R
                  XU5      n[	        U R                  XU5      nU Vs0 s H  ofXF   SXV   -  -   _M     sn$ U R                  [         R                  " S5      :X  a  [        S5      eU R                  S:  a  [        S5      eUc  [        U R                  5      nU Vs/ s H  owS:  a  XpR                  -   OUPM     nn[        X#5      n[        X5      n	SU 4/n
[        X9U5       HA  u  pn/ nU
 H1  u  p[        XX+5      u  nnUR!                  US-   U4US	-   U4/5        M3     Un
MC     [#        U
5      $ s  snf s  snf )
a  
Single-level n-dimensional Discrete Wavelet Transform.

Parameters
----------
data : array_like
    n-dimensional array with input data.
wavelet : Wavelet object or name string, or tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or tuple of string, optional
    Signal extension mode used in the decomposition,
    see :ref:`Modes <ref-modes>`. This can also be a tuple of modes
    specifying the mode to use on each axis in ``axes``.
axes : sequence of ints, optional
    Axes over which to compute the DWT. Repeated elements mean the DWT will
    be performed multiple times along these axes. A value of ``None`` (the
    default) selects all axes.

    Axes may be repeated, but information about the original size may be
    lost if it is not divisible by ``2 ** nrepeats``. The reconstruction
    will be larger, with additional values derived according to the
    ``mode`` parameter. ``pywt.wavedecn`` should be used for multilevel
    decomposition.

Returns
-------
coeffs : dict
    Results are arranged in a dictionary, where key specifies
    the transform type on each dimension and value is a n-dimensional
    coefficients array.

    For example, for a 2D case the result will look something like this::

        {'aa': <coeffs>  # A(LL) - approx. on 1st dim, approx. on 2nd dim
         'ad': <coeffs>  # V(LH) - approx. on 1st dim, det. on 2nd dim
         'da': <coeffs>  # H(HL) - det. on 1st dim, approx. on 2nd dim
         'dd': <coeffs>  # D(HH) - det. on 1st dim, det. on 2nd dim
        }

    For user-specified ``axes``, the order of the characters in the
    dictionary keys map to the specified ``axes``.

              ?objectz"Input must be a numeric array-liker   zInput data must be at least 1Dr    ad)r   r   r   iscomplexobjr   realimagdtype	TypeErrorr   r   ranger	   r
   zipr   extenddict)r   r   r   r    r1   r2   kr.   modeswaveletsr%   axiswav
new_coeffssubbandxcAcDs                     r"   r   r   w   sz   Z ::dD!6!6DIIwd3DIIwd33784a47R$'\))488zzRXXh''<==yy1}9::|TYY3784aUA		M)4D8D'E!'0H4j\Ftu54
 JGad1FB#r2 '#r24 5 !  6 <- 9 9s   /F.Fc                 \   U R                  5        VVs/ s H  u  pUb  M
  UPM     nnnU(       a  [        SU S35      eU R                  5        VVs/ s H!  u  p[        U5      [        S5      ::  a  M  UPM#     nnnU(       a  [        SU S35      eU  Vs/ s H  n[        U5      PM     nn[        [        R
                  " U5      5      S:  a  [        S5      eU R                  5        VVs0 s H  u  pU[        R                  " U5      _M     snn$ s  snnf s  snnf s  snf s  snnf )Nz4The following detail coefficients were set to None:
zr
For multilevel transforms, rather than setting
	coeffs[key] = None
use
	coeffs[key] = np.zeros_like(coeffs[key])
r   zLThe following invalid keys were found in the detail coefficient dictionary: .r   z4All detail coefficient names must have equal length.)itemsr   setr   r   r   r   )r%   r9   vmissing_keysinvalid_keyskey_lengthss         r"   _fix_coeffsrK      s   "(,,.>.$!AA.L>Cn ;;< 	< #),,. -.$!A#d)+ .L -''3nA78 	8 $**6a3q66K*
299[!"Q&BD 	D *08Arzz!}88- ?- +
 9s"   	DDD5DD#0#D(c                   ^^ U R                  5        VVs0 s H  u  pEUc  M
  XE_M     n nnU R                  5        VVs0 s H  u  pEUc  M
  XE_M     n nn[        U 5      n [        (       d  [        S U R	                  5        5       5      (       ax  U R                  5        VVs0 s H  u  pEXER
                  _M     nnnU R                  5        VVs0 s H  u  pEXER                  _M     nnn[        XaX#5      S[        XqX#5      -  -   $ [        S U  5       5      m U4S jU R                  5        5       n[        U5      m[        U4S jU 5       5      (       a  [        S5      eUc  [        T5      nTn	O[        T5      n	U V
s/ s H  oS	:  a  X-   OU
PM     nn
[        X#5      n[        X5      n[!        [#        [%        ['        X<U5      5      5      5       GH0  u  nu  pnUS	:  d  X:  a  [)        S
5      e0 n[+        SUS9 Vs/ s H  nSR-                  U5      PM     nnU H  nU R/                  US-   S5      nU R/                  US-   S5      nUb  Ub  UR0                  UR0                  :w  a  UR0                  R2                  S:X  d  UR0                  R2                  S:X  a  [4        R6                  nO[4        R8                  n[4        R:                  " UUS9n[4        R:                  " UUS9n[=        UUXU5      UU'   M     Un GM3     U S   $ s  snnf s  snnf s  snnf s  snnf ! [         a    [        S5      ef = fs  sn
f s  snf )a  
Single-level n-dimensional Inverse Discrete Wavelet Transform.

Parameters
----------
coeffs: dict
    Dictionary as in output of ``dwtn``. Missing or ``None`` items
    will be treated as zeros.
wavelet : Wavelet object or name string, or tuple of wavelets
    Wavelet to use.  This can also be a tuple containing a wavelet to
    apply along each axis in ``axes``.
mode : str or list of string, optional
    Signal extension mode used in the decomposition,
    see :ref:`Modes <ref-modes>`. This can also be a tuple of modes
    specifying the mode to use on each axis in ``axes``.
axes : sequence of ints, optional
    Axes over which to compute the IDWT. Repeated elements mean the IDWT
    will be performed multiple times along these axes. A value of ``None``
    (the default) selects all axes.

    For the most accurate reconstruction, the axes should be provided in
    the same order as they were provided to ``dwtn``.

Returns
-------
data: ndarray
    Original signal reconstructed from input data.

Nc              3   N   #    U  H  n[         R                  " U5      v   M     g 7fN)r   r0   ).0rG   s     r"   	<genexpr>idwtn.<locals>.<genexpr>  s     <Oq""Os   #%r+   c              3   8   #    U  H  n[        U5      v   M     g 7frN   )r   )rO   keys     r"   rP   rQ     s     4VcSVs   c              3   l   >#    U  H)  u  pUc  M
  [        U5      T:X  d  M  UR                  v   M+     g 7frN   )r   shape)rO   r9   rG   ndim_transforms      r"   rP   rQ     s3      GNDA  -0V~-E  Ns   	444z8`coeffs` must contain at least one non-null wavelet bandc              3   ,   >#    U  H	  oT:g  v   M     g 7frN    )rO   scoeff_shapes     r"   rP   rQ     s     
2\\s   z,`coeffs` must all be of equal size (or None)r   z!Axis greater than data dimensionsr   )repeatr-   r.   r/   c)r3   )rE   rK   r   anyvaluesr1   r2   r   maxnextStopIterationr   r5   r   r	   r
   reversedlist	enumerater6   r   r   joingetr3   kindr   
complex128float64r   r   )r%   r   r   r    r9   rG   real_coeffsimag_coeffscoeff_shapesr   r.   r:   r;   
key_lengthr<   r=   r>   coefnew_keysrS   LHr3   rZ   rV   s                          @@r"   r   r      s   @  &||~?~tqdad~F?  &||~?~tqdad~F?  F<FMMO<<<-3\\^<^TQq&&y^<-3\\^<^TQq&&y^<kD7U;<<= 	> 4V44N!GFLLN G<( 
2\
222GHH|^$;.23dAAH1$dD3D'E!'0H)13tu567*9%
%T!8t|?@@
.5d:.NO.NdBGGDM.NOC

39d+A

39d+A}77agg%ww||s*aggllc.A " "



1E2A

1E2A'1c>JsO  +*9. ":y @ @ =<  !   ! 	!! 4 Ps9   	LL	LL#LL%%L+ MM	+M)	symmetric))rr   N)__doc__	itertoolsr   numpyr   _c99_configr   _extensions._dwtr   r   _utilsr   r	   r
   __all__r   r   r   rK   r   rX   r#   r"   <module>r|      sB   
   * 1 B B
,2@j).XGT94\r#   