o
    jo                     @   sv  d dl Z d dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ e
 Zed Zejdg dd	d
 Zdd Zdd Zdd Zejdg ddd Zdd Zdd Zejdg ddd Zdd Zdd Zdd Zejdg dd d! Zd"d# Z d$d% Z!ejdg dd&d' Z"d(d) Z#ejd*g d+ejd,ej$ej%gd-d. Z&dS )/    N)assert_almost_equalassert_array_equalassert_equal)data)_supported_float_type)pyramids).r   channel_axis)r      c                 C   s`   t  }|j\}}}tj|d| d}tj|d| d}t|| d}t|j|d |d |f d S Nr
   sourceZdestination   	downscaler   )r   	astronautshapenpmoveaxisr   pyramid_reducer   )r   imagerowscolsdimZout_out r   f/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/skimage/transform/tests/test_pyramids.pytest_pyramid_reduce_rgb   s   r   c                  C   sz   t j\} }tjt dd d}t|j| d |d f tt|ddd tjt dd dd}tt|tt  ddd d S )Nr   r         ?decimalT)r   r   preserve_range
image_grayr   r   r   r   r   r   Zptpr   r   Zout1Zout2r   r   r   test_pyramid_reduce_gray   s   
"r%   c                  C   sp   t j\} }tt }t|j| d |d f tt|ddd tjt dd}tt|tt  ddd d S )Nr   r   r   T)r!   r"   r$   r   r   r   !test_pyramid_reduce_gray_defaults&   s   

"r&   c                  C   sJ   dD ] } t jjd|   }tj|dd d}t |jd }t|j| qd S Nr	   r         )   r   r   )r   randomrandnr   r   asarrayr   r   ndimimgr   expected_shaper   r   r   test_pyramid_reduce_nd/      r3   )r   r	   r   r
   c                 C   sf   t  }|j\}}}tj|d| d}tj|d| d}|d |d g}|| |j | t	|j| d S )Nr
   r   r   upscaler   )
r   r   r   r   r   r   pyramid_expandinsertr0   r   )r   r   r   r   r   r   r2   r   r   r   test_pyramid_expand_rgb7   s   r;   c                  C   s4   t j\} }tjt dd}t|j| d |d f d S )Nr   )r8   )r#   r   r   r9   r   )r   r   r   r   r   r   test_pyramid_expand_grayB   s   
r<   c                  C   sJ   dD ] } t jjd|   }tj|dd d}t |jd }t|j| qd S )Nr(   )r*   r   r7   )r   r,   r-   r   r9   r.   r   r   r/   r   r   r   test_pyramid_expand_ndH   r4   r=   c           	      C      t  }|j\}}}tj|d| d}tj|d| d}t|D ]"\}}|d|  |d|  g}|| |j	 | |jt
|ks@J qd S r   )r   r   r   r   r   r   pyramid_gaussian	enumerater:   r0   tuple	r   r   r   r   r   pyramidlayerr   layer_shaper   r   r   test_build_gaussian_pyramid_rgbP      rF   c                  C   sT   t j\} }tjt dd d}t|D ]\}}| d|  |d|  f}t|j| qd S )Nr   r   r#   r   r   r?   r@   r   r   r   rC   rD   r   rE   r   r   r    test_build_gaussian_pyramid_gray\   s   
rJ   c                  C   N   t j\} }tt }t|D ]\}}| d|  |d|  f}t|j| qd S Nr   rH   rI   r   r   r   )test_build_gaussian_pyramid_gray_defaultsd      

rM   c                  C   d   dD ]-} t jjd|   }t |j}tj|dd d}t|D ]\}}|d|  }t|j| qqd S r'   )	r   r,   r-   r.   r   r   r?   r@   r   r0   r1   Zoriginal_shaperC   rD   r   rE   r   r   r   test_build_gaussian_pyramid_ndl      rQ   c           	      C   r>   r   )r   r   r   r   r   r   pyramid_laplacianr@   r:   r0   rA   rB   r   r   r    test_build_laplacian_pyramid_rgbv   rG   rT   c                  C   rK   rL   )r#   r   r   rS   r@   r   rI   r   r   r   %test_build_laplacian_pyramid_defaults   rN   rU   c                  C   rO   )Nr(   )   r   r   )	r   r,   r-   r.   r   r   rS   r@   r   rP   r   r   r   test_build_laplacian_pyramid_nd   rR   rW   c                 C   s  dD ]|}| d u rd}|}nd}t |d }d}t|}|| | | t|}t|}tj||| d}t	t
t||}t|D ]/\}	}
| d u rO|
j}n|
j|  |ksXJ t|
j}||  t|}|	|k rrt|dksrJ qCt||	 |dks~J qd S )N)r   r)         )    r+   r	   rX   r   )r	   r	   )lenlistr:   rA   r   Zonesr   rS   mathceillogmaxr@   r   popr   )r   r   r   Zshape_without_channelsr0   Z
n_channelsr1   rC   Z	max_layerrD   r   Zout_shape_without_channelsr   r   r   !test_laplacian_pyramid_max_layers   s8   



rb   c                   C   sn   t t td W d    n1 sw   Y  t t td W d    d S 1 s0w   Y  d S )NgGz?r5   )pytestZraises
ValueErrorr   Z_check_factorr   r   r   r   test_check_factor   s   "re   dtype)Zfloat16Zfloat32Zfloat64Zuint8Zint64pyramid_funcc                    s|   t   t jdtdd tjdd|}W d    n1 s!w   Y  | |}t| t	 fdd|D s<J d S )Nignorez!invalid value encountered in cast)actioncategorymessagerZ   r+   c                    s   g | ]}|j  kqS r   )rf   ).0ZimZfloat_dtyper   r   
<listcomp>   s    z.test_pyramid_dtype_support.<locals>.<listcomp>)
warningscatch_warningsfilterwarningsRuntimeWarningr   r,   r-   Zastyper   all)rg   rf   r1   rC   r   rm   r   test_pyramid_dtype_support   s   

 rt   )'r]   ro   rc   numpyr   Znumpy.testingr   r   r   Zskimager   Zskimage._shared.utilsr   Zskimage.transformr   r   r   r#   markZparametrizer   r%   r&   r3   r;   r<   r=   rF   rJ   rM   rQ   rT   rU   rW   rb   re   r?   rS   rt   r   r   r   r   <module>   sH    
		






%