
    9iz                     R    S SK rSSKJr  S r\R
                  " SS9SS.S j5       rg)	    N   )utilsc                    U R                   R                  S:X  aj  U R                  S5      n[        R                  " U5      n[        R                  " UR                  S5      5      n[        R
                  " U5      S   nXE   nON[        R                  " U R                  S5      SSS9u  pbn[        R                  " UR                  S5      SS9u  pT[        R                  " U5      U R                  -  n[        R                  " U5      UR                  -  n[        R                  " XxU5      n	X   R                  U R                  5      $ )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/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/exposure/histogram_matching.py_match_cumulative_cdfr       s   
 ||C^^B'
[[,
kk("2"22"67 jj-a0!.-/YYNN2t4.
*

 $&99X-=-=b-AQU#V  IIj)FKK7MYY{+hmm;Nii{KO&..v||<<    )r      )channel_arg_positions)channel_axisc                    U R                   UR                   :w  a  [        S5      eUb  U R                  S   UR                  S   :w  a  [        S5      e[        R                  " U R                  U R
                  S9n[        U R                  S   5       H  n[        U SU4   USU4   5      nXSSU4'   M!     O[        X5      nUR
                  R                  S:X  a0  [        R                  " U R
                  5      nUR                  USS9nU$ )	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.

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[[_-G3c7l#YsG|%<O %4CL!	 . (9}}S //<	...7Nr!   )numpyr   _sharedr   r    channel_as_last_axisr4    r!   r   <module>r9      s2     =6 &97; ; :;r!   