
    1-Ph%              
          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                            d ej        d           ej        d	           ej        d
d	d          fej                            d           ej        d           ej        d          fg          d             Z G d d          ZdS )    N)assert_almost_equalassert_array_almost_equal)data)exposure)_supported_float_type)histogram_matchingzarray, template, expected_array
   d   	         c                 P    t          j        | |          }t          ||           d S N)r   _match_cumulative_cdfr   )arraytemplateexpected_arraymatcheds       n/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/exposure/tests/test_histogram_matching.pytest_match_array_valuesr      s.     !6uhGGG g~66666    c            	       .   e Zd Z ej                    Z ej                    Ze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	        
                    dd          d             Zej	        
                    d	ej        ej        ej        g          d
             Ze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dS )TestMatchHistogramzimage, reference, channel_axisNr   c                    t          j        |||          }|                     |          }|                     |          }t          t	          |                    D ]t}||         \  }}	||         \  }
}t          |
          D ]L\  }}t          j        ||z
                                            }t          ||         |	|         d           MudS )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XX99'BB;;IFFS--.. 	 	G4A'4J110;G0D-N-$-n$=$=   = f%5%EFFNNPP
#%a(*=j*IST    		 	r   r   )r   r   r   c                    t          j        | j        d|          }t          j        | j        d|          }t	          j        |||          }|j        |j        k    sJ t          j        ||d          }t          j        ||d          }|                     |          }|                     |          }t          t          |                    D ]t}||         \  }}	||         \  }
}t          |
          D ]L\  }}t          j        ||z
                                            }t          ||         |	|         d           MudS )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   sb   
 DNB==K 12|DD	+E9<XXX}+++++g|R88K	<<<	99'BB;;IFFS--.. 	 	G4A'4J110;G0D-N-$-n$=$=   = f%5%EFFNNPP
#%a(*=j*IST    		 	r   r<   c                     | j                             |d          }| j                            |d          }t          j        ||          }|j        t          |          k    sJ dS )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   sm     %%e%%88%,,U,??	+E9==} 5e < <<<<<<<r   zimage, referencec                     t          j        t                    5  t          j        ||           d d d            d S # 1 swxY w Y   d S 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   s    
 ]:&& 	8 	8%eY777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   =AAc                    |j         dk    r|                    ddd          }t          j        |dd          }g }|D ]n}t          j        |d          \  }}t          j        |                              t          j                  }||d	         z  }|                    ||f           ot          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8EQ777 	E 	EG%'Ywd%K%K%K"NF "	& 1 1 8 8 D D!22!661B CDDDDz,f5555r   c                 d   | j         }| j        }| j                             t          j                  }| j                            t          j        d          }t          j        ||          }t          j        ||          }t          |                    t          j                  |           dS )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    >(N))"*55	)00%0HH.xFF
/	=II!*"3"3BJ"?"?MMMMMr   )__name__
__module____qualname__r   chelsear:   	astronautr;   rD   markparametrizer7   r=   r'   float16float32rP   rB   rG   classmethodr#   ra    r   r   r   r      s       I!4>##L[(b)qqq!!!QwaaaAg!6=	
   & [^Z88  98. [Wrz2:rz&JKK= = LK= [
\!!!QQQ'*	+i111a.@,-OP 8 8	 8 6 6 [6$N N N N 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      sR        H H H H H H H H             7 7 7 7 7 7 / / / / / / %	2		#		!S"(=(=>			GBGAJJ

3 7 7 7aN aN aN aN aN aN aN aN aN aNr   