
    |hz                     V    d dl ZddlmZ d Z ej
                  d      ddd       Zy)	    N   )utilsc                    | j                   j                  dk(  rh| j                  d      }t        j                  |      }t        j                  |j                  d            }t        j
                  |      d   }||   }nTt        j                  | j                  d      dd      \  }}}t        j                  |j                  d      d      \  }}t        j                  |      | j                  z  }t        j                  |      |j                  z  }t        j                  |||      }	|	|   j                  | j                        S )z
    Return modified source array so that the cumulative density function of
    its values matches the cumulative density function of the template.
    ur   T)return_inversereturn_counts)r	   )dtypekindreshapenpbincountnonzerouniquecumsumsizeinterpshape)
sourcetemplate
src_lookup
src_countstmpl_countstmpl_values
src_valuessrc_quantilestmpl_quantilesinterp_a_valuess
             b/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/exposure/histogram_matching.py_match_cumulative_cdfr       s   
 ||C^^B'
[[,
kk("2"22"67 jj-a0!+.-/YYNN2t4.
*
J
 $&99X-=-=b-AQU#V [ IIj)FKK7MYY{+hmm;Nii~{KO:&..v||<<    )r      )channel_arg_positions)channel_axisc                    | j                   |j                   k7  rt        d      || j                  d   |j                  d   k7  rt        d      t        j                  | j                  | j
                        }t        | j                  d         D ]  }t        | d|f   |d|f         }||d|f<   ! nt        | |      }|j
                  j                  dk(  r2t        j                  | j
                        }|j                  |d      }|S )	aw  Adjust an image so that its cumulative histogram matches that of another.

    The adjustment is applied separately for each channel.

    Parameters
    ----------
    image : ndarray
        Input image. Can be gray-scale or in color.
    reference : ndarray
        Image to match histogram of. Must have the same number of channels as
        image.
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.

    Returns
    -------
    matched : ndarray
        Transformed input image.

    Raises
    ------
    ValueError
        Thrown when the number of channels in the input image and the reference
        differ.

    References
    ----------
    .. [1] http://paulbourke.net/miscellaneous/equalisation/

    z:Image and reference must have the same number of channels.r   zENumber of channels in the input image and reference image must match!)r
   .fF)copy)ndim
ValueErrorr   r   emptyr
   ranger    r   r   _supported_float_typeastype)image	referencer$   matchedchannelmatched_channel	out_dtypes          r   match_histogramsr4   !   s
   D zzY^^#K
 	
 ;;r?ioob11. 
 ((5;;ekk:U[[_- 	4G3c7l#YsG|%<O %4GCL!		4 (y9}}S //<	...7Nr!   )numpyr   _sharedr   r    channel_as_last_axisr4    r!   r   <module>r9      s4     =6 &97; ; :;r!   