o
    :ήc                     @   s@  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
mZmZ d dlmZ d dlmZ d dlmZmZ ee
 ZedkZd	d
 Zejdg ddd Zdd Zdd Zdd Zdd Zdd Z dd Z!ej"ej#ej$ej%gZ&ejde&dd Z'dd Z(ej$ej%gZ)ejde)dd  Z*d!d" Z+d#d$ Z,d%d& Z-dS )'    N)assert_array_equalassert_equal)ndimage)datacolor
morphology)expected_warnings)img_as_bool)binarygrayg?c                  C   sT   t d} ttd dd df | }tttd dd df | }t|| d S )N   d      	r   squarer
   binary_erosionbw_imgr	   r   erosionr   	footprint
binary_resgray_res r   K/tmp/pip-target-vg8gfxp4/lib/python/skimage/morphology/tests/test_binary.pytest_non_square_image   s   
 r   function)r   binary_dilationbinary_closingbinary_openingc                 C   sH   t dg tt| ttdd W d    d S 1 sw   Y  d S )Nz%`selem` is a deprecated argument namer   )selem)r   getattrr
   r   r   r   )r   r   r   r   test_selem_kwarg_deprecation   s   "r!   c                  C   4   t d} tt| }ttt| }t|| d S Nr   r   r   r   r   r   test_binary_erosion       
r$   c                  C   r"   r#   )	r   r   r
   r   r   r	   r   dilationr   r   r   r   r   test_binary_dilation'   r%   r'   c                  C   r"   r#   )	r   r   r
   r   r   r	   r   closingr   r   r   r   r   test_binary_closing.   r%   r)   c                  C   r"   r#   )	r   r   r
   r   r   r	   r   openingr   r   r   r   r   test_binary_opening5   r%   r+   c                  C   s\   t jdt jd} t jdtd}d|ddddf< t|| }tt	|| }t
|| d S )N)   r,   dtype)   r/   T      )nponesuint8zerosboolr
   r   r	   r   r   r   )r   imgr   r   r   r   r   test_footprint_overflow<   s   r8   c                  C   sr   t jt jfD ]0} tjdtjd}td}t|}| }| |||d t||ks.J t	|| || qd S )N)r   r   r-   )
   r9   out)
r
   r   r   r2   r3   r4   
zeros_likecopyanyr   )funcr   r7   r;   	out_savedr   r   r   test_out_argumentE   s   

rA   c                 C   s   t jdd}tg dg dg dg dg dg dg dg dg dg dg dg dg dgtj}| ||}| |}t|| d S )N   )radius)
r   r   r   r   r   r   r   r   r   r   )
r   r   rB   rB   rB   rB   rB   rB   r   r   )
r   r   rB   rB   rB   r   r   rB   r   r   )r   diamondr2   arrayr4   r   )r   r   imageim_expectedim_testr   r   r   test_default_footprintT   s(   

rI   c                  C   sn   t dt} d| ddddddf< t| }t jdtd}tdd|ddddddf< t|| d S )N   rK   rK   rB   r0   r-   r      )r2   r5   r6   r
   r   ndigenerate_binary_structurer   )rF   openedimage_expectedr   r   r   "test_3d_fallback_default_footprinti   s   
"rR   c                 C   sN   t dt}d|ddddddf< t jdt jd}| ||}t|| d S )NrJ   rB   r0   rL   )r   r   r   r-   )r2   r5   r6   r3   r4   r   )r   rF   cube	new_imager   r   r   test_3d_fallback_cube_footprinty   s
   
rU   c                  C   s   t dt j} d| ddddf< d| ddddf< d| d	< t| }t| }tdd
}tj| |d}tj| |d}t|| t|| d S )N	   rW    @  r0   rL      r        r]   rB   )	structure)	r2   r5   uint16r
   r   r   rN   rO   r   )rF   
bin_opened
bin_closedr   ndimage_openedndimage_closedr   r   r   test_2d_ndimage_equivalence   s   


rd   c                  C   s   t dt j} d| ddddf< d| ddddf< d| d	< t| }t| }t j| t jd
}t j| t jd
}tj| |d tj| |d t|j	t
 t|j	t
 t|j	t j t|j	t j d S )NrV   rX   r0   rL   rY   r   rZ   r[   r\   r-   r:   r2   r5   r_   r
   r   r   
empty_liker4   r   r.   r6   rF   r`   ra   
int_opened
int_closedr   r   r   test_binary_output_2d   s   

rj   c                  C   s   t dt j} d| ddddddf< d| ddddddf< d| d	< t| }t| }t j| t jd
}t j| t jd
}tj| |d tj| |d t|j	t
 t|j	t
 t|j	t j t|j	t j d S )N)rW   rW   rW   rX   r0   rL   rY   r   rZ   r[   )r]   r]   r]   r-   r:   re   rg   r   r   r   test_binary_output_3d   s   

rk   ).numpyr2   pytestnumpy.testingr   r   scipyr   rN   skimager   r   r   skimage._shared._warningsr   skimage.utilr	   skimage.morphologyr
   r   rgb2gray	astronautr7   r   r   markparametrizer!   r$   r'   r)   r+   r8   rA   r   r   r   r   binary_functionsrI   rR   binary_3d_fallback_functionsrU   rd   rj   rk   r   r   r   r   <module>   sD    
	


