o
    h                     @   s6  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mZmZmZ ejd e ZdZeeeejjej   d dZeejZd	d
 Zejdejejejgdd Z dd Z!ejdejejejgdd Z"dd Z#dd Z$dd Z%dd Z&ejdejejejgdd Z'dd Z(dS )    N)assert_equalassert_almost_equal)data)expected_warnings)peak_signal_noise_rationormalized_root_msemean_squared_errornormalized_mutual_information   g      4@   c                  C   s    d} t tt}t|| dd dS )a=   Tests vs. imdiff result from the following IPOL article and code:
    https://www.ipol.im/pub/art/2011/g_lmii/.

    Notes
    -----
    To generate p_IPOL, we need a local copy of cam_noisy:

    >>> from skimage import io
    >>> io.imsave('/tmp/cam_noisy.png', cam_noisy)

    Then, we use the following command:
    $ ./imdiff -m psnr <path to camera.png>/camera.png /tmp/cam_noisy.png

    Values for current data.camera() calculated by Gregory Lee on Sep, 2020.
    Available at:
    https://github.com/scikit-image/scikit-image/pull/4913#issuecomment-700653165
    gah6@   decimalN)r   cam	cam_noisyr   )p_IPOLp r   d/var/www/html/scripts/venv/lib/python3.10/site-packages/skimage/metrics/tests/test_simple_metrics.pytest_PSNR_vs_IPOL   s   
r   dtypec                 C   s:  t tt}td j| dd}td j| dd}t ||dd}|jtjks&J | tjkr-dnd}t|||d t td t	td dd}t|||d t
d	g t td t	td }W d    n1 sgw   Y  t|||d t
d	g t td t	td }W d    n1 sw   Y  t|||d d S )
Ng     o@F)copy   )
data_range   r
   r   zInputs have mismatched dtype)r   r   r   astyper   npfloat64float16r   float32r   )r   p_uint8camf
camf_noisy	p_float64r   p_mixedr   r   r   test_PSNR_float)   s.   
r%   c                   C   sJ   t t tttd dd d f  W d    d S 1 sw   Y  d S )N)pytestraises
ValueErrorr   r   r   r   r   r   test_PSNR_errorsF   s   "r*   c                 C   s   t jd| d}t jg d| d}t||dd}|jt jksJ t|dt |  tt||dddt d  tt||d	dd|	 |
    tt|t |d	dd|	 |
    d S )
Nr   )r   )g               @r+   r+   meannormalizationr   	euclideanr   zmin-max)r   onesasarrayr   r   r   r   r,   sqrtmaxminr   r   )r   xynrmser   r   r   
test_NRMSEL   s    r8   c                  C   sH   t tj} ttj}ttt tt| | ttt tt| | d S )N)r   r   r   r   r   r   r   r   )r!   
cam_noisyfr   r   r   test_NRMSE_no_int_overflow^   s   

r:   c                  C   s   t d} tt t| d d |  W d    n1 sw   Y  tt t| | dd W d    d S 1 s;w   Y  d S )Nr   r&   foor-   )r   r0   r'   r(   r)   r   )r5   r   r   r   test_NRMSE_errorsg   s   
"r<   c                   C   s,   t tttd ttttttk sJ d S )N   )r   r	   r   r   r   r   r   r   test_nmiq   s   r>   c                   C   s6   t td d d df td dd d f dksJ d S )Ni  r   )r	   r   r   r   r   r   test_nmi_different_sizesw   s   6r?   c                 C   sZ   t j }|d| }|d| }t||dd}|jt jks$J t|ddd d S )N)d   r@   
   binsr   r=   r   )r   randomdefault_rngr   r	   r   r   r   )r   rngrandom1random2nmir   r   r   test_nmi_random{   s   
rJ   c                  C   s,   t jd\} }tt| |ddddd d S )N)r=   rA   r@   r@   rA   rB   r   r=   r   )r   rD   r   r	   )rG   rH   r   r   r   test_nmi_random_3d   s   
rK   ))numpyr   r'   numpy.testingr   r   skimager   skimage._shared._warningsr   skimage.metricsr   r   r   r	   rD   seedcamerar   sigmacliprandnshaper   r   r   r   markparametrizer   r   r   r%   r*   r8   r:   r<   r>   r?   rJ   rK   r   r   r   r   <module>   s0     

	

	