o
    :ήc                     @   sD   d dl ZddlmZ dd Zejdde ddd	d
dZdS )    N   )utilsc           
      C   sn   t j|  ddd\}}}t j| 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.
    T)return_inversereturn_counts)r   )npuniqueravelcumsumsizeinterpreshapeshape)
sourcetemplate
src_valuessrc_unique_indices
src_countstmpl_valuestmpl_countssrc_quantilestmpl_quantilesinterp_a_values r   J/tmp/pip-target-vg8gfxp4/lib/python/skimage/exposure/histogram_matching.py_match_cumulative_cdf   s   
r   )r      )channel_arg_positionsF)channel_axismultichannelc                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 )
a  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.
    multichannel : bool, optional
        Apply the matching separately for each channel. This argument is
        deprecated: specify `channel_axis` instead.

    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.NzENumber of channels in the input image and reference image must match!)dtype.fF)copy)ndim
ValueErrorr   r   emptyr    ranger   kindr   _supported_float_typeastype)image	referencer   r   matchedchannelmatched_channel	out_dtyper   r   r   match_histograms   s"   '

r0   )numpyr   _sharedr   r   channel_as_last_axisdeprecate_multichannel_kwargr0   r   r   r   r   <module>   s    
