U
    ?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   )Zp_IPOLp r   [/var/www/html/venv/lib/python3.8/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sLt| tjkrZdnd}t	|||d t td t
td dd}t	|||d td	g t td t
td }W 5 Q R X t	|||d td	g t td t
td }W 5 Q R X t	|||d d S )
Ng     o@F)copy   )Z
data_range   r
   r   zInputs have mismatched dtype)r   r   r   astyper   npfloat64AssertionErrorfloat16r   float32r   )r   Zp_uint8camfZ
camf_noisyZ	p_float64r   Zp_mixedr   r   r   test_PSNR_float)   s*    
r    c                	   C   s4   t t  tttd dd d f  W 5 Q R X 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ddddg| d}t||dd}|jt jksBt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        g       @meanZnormalizationr   Z	euclideanr   zmin-max)r   onesZasarrayr   r   r   r   r   r&   sqrtmaxminr   r   )r   xyZnrmser   r   r   
test_NRMSEL   s     r.   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   Z
cam_noisyfr   r   r   test_NRMSE_no_int_overflow^   s    

r/   c               	   C   sZ   t d} tt t| d d |  W 5 Q R X tt t| | dd W 5 Q R X d S )Nr   r!   Zfoor'   )r   r(   r"   r#   r$   r   )r,   r   r   r   test_NRMSE_errorsg   s
    
r0   c                   C   s,   t tttd ttttttk s(td S )N   )r   r	   r   r   r   r   r   r   r   test_nmiq   s    r2   c                   C   s6   t td d d df td dd d f dks2td S )Ni  r   )r	   r   r   r   r   r   r   test_nmi_different_sizesw   s    r3   c                 C   sZ   t j }|d| }|d| }t||dd}|jt jksHtt|ddd d S )N)d   r4   
   Zbinsr   r1   r   )	r   randomZdefault_rngr   r	   r   r   r   r   )r   rngrandom1random2Znmir   r   r   test_nmi_random{   s    
r;   c                  C   s,   t jd\} }tt| |ddddd d S )N)r1   r5   r4   r4   r5   r6   r   r1   r   )r   r7   r   r	   )r9   r:   r   r   r   test_nmi_random_3d   s    r<   ))numpyr   r"   Znumpy.testingr   r   Zskimager   Zskimage._shared._warningsr   Zskimage.metricsr   r   r   r	   r7   seedcamerar   sigmaZclipZrandnshaper   r   r   r   markZparametrizer   r   r   r    r%   r.   r/   r0   r2   r3   r;   r<   r   r   r   r   <module>   s.    

	

	