
    _h%              
          d dl Zd dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ ej                  j                  d ej                  d       ej                  d	       ej                  d
d	d      fej                   j#                  d       ej$                  d       ej$                  d      fg      d        Z G d d      Zy)    N)assert_almost_equalassert_array_almost_equal)data)exposure)_supported_float_type)histogram_matchingzarray, template, expected_array
   d   	         c                 H    t        j                  | |      }t        ||       y N)r   _match_cumulative_cdfr   )arraytemplateexpected_arraymatcheds       h/var/www/html/engine/venv/lib/python3.12/site-packages/skimage/exposure/tests/test_histogram_matching.pytest_match_array_valuesr      s"     !66uhGG g~6    c            	       $   e Zd Z ej                         Z ej                         Zej                  j                  deedfedddddf   edddddf   dfg      d        Zej                  j                  dd      d        Zej                  j                  d	ej                  ej                  ej                   g      d
        Zej                  j                  deedddddf   fedddddf   efg      d        Zed        Zd Zy)TestMatchHistogramzimage, reference, channel_axisNr   c                 d   t        j                  |||      }| j                  |      }| j                  |      }t        t	        |            D ]_  }||   \  }}	||   \  }
}t        |
      D ]?  \  }}t        j                  ||z
        j                         }t        ||   |	|   d       A a y)sAssert 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_histogramsz(TestMatchHistogram.test_match_histograms   s     ++E9<X99'B;;IFS-. 	G4A'4J110;G0D-N-$-n$=  = ff%5%EFNNP
#%a(*=j*IST		r   r   )r   r   r   c                 z   t        j                  | j                  d|      }t        j                  | j                  d|      }t	        j
                  |||      }|j                  |j                  k(  sJ t        j                  ||d      }t        j                  ||d      }| j                  |      }| j                  |      }t        t        |            D ]_  }||   \  }}	||   \  }
}t        |
      D ]?  \  }}t        j                  ||z
        j                         }t        ||   |	|   d       A a y)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.   r/   r0   r1   r2   r3   r4   r5   r6   s                  r   "test_match_histograms_channel_axisz5TestMatchHistogram.test_match_histograms_channel_axis8   s+   
 DNNB=KK 1 12|D	++E9<X}}+++++g|R8KK	<<	99'B;;IFS-. 	G4A'4J110;G0D-N-$-n$=  = ff%5%EFNNP
#%a(*=j*IST		r   r<   c                     | j                   j                  |d      }| j                  j                  |d      }t        j                  ||      }|j
                  t        |      k(  sJ y)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_dtypez4TestMatchHistogram.test_match_histograms_float_dtypeP   sb     %%e%%8%%,,U,?	++E9=}} 5e <<<<r   zimage, referencec                     t        j                  t              5  t        j                  ||       d d d        y # 1 sw Y   y xY wr   )pytestraises
ValueErrorr   r"   )r*   r+   r,   s      r   ,test_raises_value_error_on_channels_mismatchz?TestMatchHistogram.test_raises_value_error_on_channels_mismatchX   s5    
 ]]:& 	8%%eY7	8 	8 	8s	   :Ac                    |j                   dkD  r|j                  ddd      }t        j                  |dd      }g }|D ]i  }t        j                  |d      \  }}t        j
                  |      j                  t        j                        }||d	   z  }|j                  ||f       k t        j                  |t        
      S )zpHelper function for calculating empirical probability density
        function of a given image for all channels   r   r   Fr   )r@   ndminT)return_countsr   )r<   )ndim	transposer'   r   uniquecumsumrA   float64appendasarrayobject)clsr+   channelschannels_pdfr/   channel_valuescountschannel_quantiless           r   r#   z1TestMatchHistogram._calculate_image_empirical_pdf`   s    
 ::>OOAq!,E88EQ7 	EG%'YYwd%K"NF "		& 1 8 8 D!22!661B CD	E zz,f55r   c                    | j                   }| j                  }| j                   j                  t        j                        }| j                  j                  t        j                  d      }t        j                  ||      }t        j                  ||      }t        |j                  t        j                        |       y)z@ensure equivalent results for float and integer-based code pathsFr?   N)r:   r;   rA   r'   rP   r   r"   r   )r*   image_u8reference_u8	image_f64reference_f64
matched_u8matched_f64s          r   !test_match_histograms_consistencyz4TestMatchHistogram.test_match_histograms_consistencys   s    >>((NN))"**5	))00%0H..xF
//	=I!*"3"3BJJ"?Mr   )__name__
__module____qualname__r   chelsear:   	astronautr;   rD   markparametrizer7   r=   r'   float16float32rP   rB   rG   classmethodr#   ra    r   r   r   r      s6   I!4>>#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'   rD   numpy.testingr   r   skimager   r   skimage._shared.utilsr   skimage.exposurer   rg   rh   arangerandomrandonesr   r   rl   r   r   <module>rv      s      H   7 / %	2			#			!S"(=>		GBGGAJ
377aN aNr   