U
    ?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rH| d}t|}t|d}t|d }|| }n4t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)Zreturn_inversereturn_counts)r   )dtypekindZreshapenpZbincountZnonzerouniqueZcumsumsizeinterpshape)
sourcetemplateZ
src_lookupZ
src_countsZtmpl_countsZtmpl_valuesZ
src_valuesZsrc_quantilesZtmpl_quantilesZinterp_a_values r   U/var/www/html/venv/lib/python3.8/site-packages/skimage/exposure/histogram_matching.py_match_cumulative_cdf   s"    



r   )r      )Zchannel_arg_positions)channel_axisc                C   s   | j |j krtd|dk	r| jd |jd kr8tdtj| j| jd}t| jd D ]*}t| d|f |d|f }||d|f< qXn
t| |}|jjdkrt	
| 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   Z_supported_float_typeZastype)image	referencer   ZmatchedZchannelZmatched_channelZ	out_dtyper   r   r   match_histograms"   s     "

r   )numpyr	   Z_sharedr   r   Zchannel_as_last_axisr   r   r   r   r   <module>   s   
