o
    j                     @   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 )a9  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   j/var/www/html/Deteccion_Ine/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   )Z
data_range   r
   r   zInputs have mismatched dtype)r   r   r   astyper   npfloat64float16r   float32r   )r   Zp_uint8camfZ
camf_noisyZ	p_float64r   Z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_errorsI   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 j|t jd  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Znormalizationr   Z	euclideanr   zmin-max)r   onesZasarrayr   r   r   r   r&   sqrtmaxminr   r   )r   xyZnrmser   r   r   
test_NRMSEO   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_overflowb   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    Zfoor'   )r   r(   r!   r"   r#   r   )r,   r   r   r   test_NRMSE_errorsm   s   
"r0   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_nmiw   s   r2   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_sizes~   s   6r3   c                 C   sZ   t j }|d| }|d| }t||dd}|jt jks$J t|ddd d S )N)d   r4   
   Zbinsr   r1   r   )r   randomZdefault_rngr   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>   s0     



	