o
    h                     @   s:   d dl ZddlmZ dd Zejddddd	d
ZdS )    N   )utilsc           
      C   s   | j jdkr$| d}t|}t|d}t|d }|| }ntj| dddd\}}}tj|ddd\}}t|| j }t||j }t	|||}	|	| | 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_values r   ^/var/www/html/scripts/venv/lib/python3.10/site-packages/skimage/exposure/histogram_matching.py_match_cumulative_cdf   s"   



r   )r      )channel_arg_positions)channel_axisc                C   s   | j |j kr
td|durC| jd |jd krtdtj| j| jd}t| jd D ]}t| d|f |d|f }||d|f< q,nt| |}|jjdkr[t	
| j}|j|d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.Nr   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_dtyper   r   r   match_histograms"   s"   "

r1   )numpyr   _sharedr   r   channel_as_last_axisr1   r   r   r   r   <module>   s
    
