
    9i%              
          S SK rS SKrS SKJrJr  S SKJr  S SKJr  S SK	J
r
  S SKJr  \R                  R                  S\R                  " S5      \R                  " S	5      \R                  " S
S	S5      4\R                   R#                  S5      \R$                  " S5      \R$                  " S5      4/5      S 5       r " S S5      rg)    N)assert_almost_equalassert_array_almost_equal)data)exposure)_supported_float_type)histogram_matchingzarray, template, expected_array
   d   	         c                 F    [         R                  " X5      n[        X25        g N)r   _match_cumulative_cdfr   )arraytemplateexpected_arraymatcheds       n/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/exposure/tests/test_histogram_matching.pytest_match_array_valuesr      s     !66uGG g6    c            	       ,   \ rS rSr\R
                  " 5       r\R                  " 5       r\	R                  R                  S\\S4\SS2SS2S4   \SS2SS2S4   S4/5      S 5       r\	R                  R                  SS5      S	 5       r\	R                  R                  S
\R                  \R                   \R"                  /5      S 5       r\	R                  R                  S\\SS2SS2S4   4\SS2SS2S4   \4/5      S 5       r\S 5       rS rSrg)TestMatchHistogram   zimage, reference, channel_axisNr   c                 R   [         R                  " XUS9nU R                  U5      nU R                  U5      n[        [	        U5      5       HX  nXg   u  pXW   u  p[        U
5       H:  u  p[        R                  " X-
  5      R                  5       n[        X   X   SS9  M<     MZ     g)kAssert that pdf of matched image is close to the reference's pdf for
all channels and all values of matchedchannel_axis   decimalN)
r   match_histograms_calculate_image_empirical_pdfrangelen	enumeratenpabsargminr   )selfimage	referencer   r   matched_pdfreference_pdfchannelreference_valuesreference_quantilesmatched_valuesmatched_quantilesimatched_value
closest_ids                  r   test_match_histograms(TestMatchHistogram.test_match_histograms   s     ++E<X99'B;;IFS-.G4A4J10;0D-N$-n$=  ff%5%EFNNP
#%(*=*IST %>	 /r   r   )r   r    r   c                 n   [         R                  " U R                  SU5      n[         R                  " U R                  SU5      n[        R
                  " X#US9nUR                  UR                  :X  d   e[         R                  " XAS5      n[         R                  " X1S5      nU R                  U5      nU R                  U5      n[        [        U5      5       HX  nXg   u  pXW   u  p[        U
5       H:  u  p[         R                  " X-
  5      R                  5       n[        X   X   SS9  M<     MZ     g)r   r   r   r    r!   N)r(   moveaxis	image_rgbtemplate_rgbr   r#   dtyper$   r%   r&   r'   r)   r*   r   )r+   r   r,   r-   r   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   s                  r   "test_match_histograms_channel_axis5TestMatchHistogram.test_match_histograms_channel_axis8   s	   
 DNNB=KK 1 12|D	++E<X}}+++++gR8KK	<	99'B;;IFS-.G4A4J10;0D-N$-n$=  ff%5%EFNNP
#%(*=*IST %>	 /r   r>   c                     U R                   R                  USS9nU R                  R                  USS9n[        R                  " X#5      nUR
                  [        U5      :X  d   eg)z-float16 or float32 inputs give float32 outputFcopyN)r<   astyper=   r   r#   r>   r   )r+   r>   r,   r-   r   s        r   !test_match_histograms_float_dtype4TestMatchHistogram.test_match_histograms_float_dtypeP   s`     %%e%%8%%,,U,?	++E=}} 5e <<<<r   zimage, referencec                     [         R                  " [        5         [        R                  " X5        S S S 5        g ! , (       d  f       g = fr   )pytestraises
ValueErrorr   r#   )r+   r,   r-   s      r   ,test_raises_value_error_on_channels_mismatch?TestMatchHistogram.test_raises_value_error_on_channels_mismatchX   s*    
 ]]:&%%e7 '&&s	   ;
A	c                    UR                   S:  a  UR                  SSS5      n[        R                  " USSS9n/ nU Hf  n[        R                  " USS9u  pV[        R
                  " U5      R                  [        R                  5      nXwS	   -  nUR                  XW45        Mh     [        R                  " U[        S
9$ )zhHelper function for calculating empirical probability density
function of a given image for all channels   r   r    Fr   )rC   ndminT)return_countsr   )r>   )ndim	transposer(   r   uniquecumsumrD   float64appendasarrayobject)clsr,   channelschannels_pdfr0   channel_valuescountschannel_quantiless           r   r$   1TestMatchHistogram._calculate_image_empirical_pdf`   s    
 ::>OOAq!,E88EQ7G%'YYwd%K"N "		& 1 8 8 D2!66 CD   zz,f55r   c                    U R                   nU R                  nU R                   R                  [        R                  5      nU R                  R                  [        R                  SS9n[
        R                  " X5      n[
        R                  " X45      n[        UR                  [        R                  5      U5        g)z@ensure equivalent results for float and integer-based code pathsFrB   N)r<   r=   rD   r(   rU   r   r#   r   )r+   image_u8reference_u8	image_f64reference_f64
matched_u8matched_f64s          r   !test_match_histograms_consistency4TestMatchHistogram.test_match_histograms_consistencys   s    >>((NN))"**5	))00%0H..xF
//	I!*"3"3BJJ"?Mr    )__name__
__module____qualname____firstlineno__r   chelsear<   	astronautr=   rH   markparametrizer8   r?   r(   float16float32rU   rE   rK   classmethodr$   rg   __static_attributes__ri   r   r   r   r      s2   I>>#L[[(b)q!QwaAg!6=	
& [[^Z8 9. [[Wrzz2::rzz&JK= L= [[
\!Q'*	+i1a.@,-OP8	8 6 6$Nr   r   )numpyr(   rH   numpy.testingr   r   skimager   r   skimage._shared.utilsr   skimage.exposurer   rp   rq   arangerandomrandonesr   r   ri   r   r   <module>r      s      H   7 / %	2		#		!S"(=>		BGGAJ
377aN aNr   