
    1-Phz                     Z    d dl ZddlmZ d Z ej        d          ddd            ZdS )	    N   )utilsc                    | j         j        dk    rs|                     d          }t          j        |          }t          j        |                    d                    }t          j        |          d         }||         }nZt          j        |                     d          dd          \  }}}t          j        |                    d          d          \  }}t          j        |          | j        z  }t          j        |          |j        z  }t          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
             c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/exposure/histogram_matching.py_match_cumulative_cdfr       s)   
 |C^^B''
[,,
k("2"22"6"677 j--a0!+.-/YNN2t4.
 .
 .
*
J
 $&9X-=-=b-A-AQU#V#V#V [ Ij))FK7MY{++hm;Ni~{KKO:&..v|<<<    )r      )channel_arg_positions)channel_axisc                   | j         |j         k    rt          d          || j        d         |j        d         k    rt          d          t          j        | j        | j                  }t          | j        d                   D ])}t          | d|f         |d|f                   }||d|f<   *nt          | |          }|j        j        dk    r0t          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.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_dtypes          r   match_histogramsr4   !   s"   D zY^##K
 
 	
 ;r?iob111.  
 (5;ek:::U[_-- 	4 	4G3c7l#YsG|%< O %4GCL!!		4 (y99}S  /<<	...77Nr!   )numpyr   _sharedr   r    channel_as_last_axisr4    r!   r   <module>r9      su             = = =6 &9997; ; ; ; ; :9; ; ;r!   