a
    
d)                     @   sn  d Z ddlZddlZddlmZ ddlmZ ddlm	Z	 G dd dZ
ejde	jd	d
fe	jd	d
fe	jd	d
fe	jd	d
fe	jd	d
fe	jd	d
fe	jdd
fe	jddfe	jdd
fe	jd	dfg
ejdejejgdd Zejdddgejdg ddd Zejdg dejddd
gdd Zejdg dejdg ddd Zd d! Zd"d# ZdS )$zX
Tests for Morphological footprints
(skimage.morphology.footprint)

Author: Damian Eads
    N)assert_equal)fetch)
footprintsc                   @   sl   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )TestFootprintsc                 C   s:   t ddD ]*}t|}tj||fdd}t|| q
dS )zTest square footprintsr      uint8dtypeN)ranger   squarenponesr   selfkactual_maskexpected_mask r   q/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/skimage/morphology/tests/test_footprints.pytest_square_footprint   s    
z$TestFootprints.test_square_footprintc                 C   sL   t ddD ]<}t ddD ],}t||}tj||fdd}t|| qq
dS )zTest rectangle footprintsr   r   r   r   N)r
   r   	rectangler   r   r   )r   ijr   r   r   r   r   test_rectangle_footprint   s
    z'TestFootprints.test_rectangle_footprintc                 C   s<   t ddD ],}t|}tj|||fdd}t|| q
dS )zTest cube footprintsr   r   r   r   N)r
   r   cuber   r   r   r   r   r   r   test_cube_footprint    s    
z"TestFootprints.test_cube_footprintc                 C   sb   t t|}d}t|D ]B}|| }||}|jdkrJ|d d t jf }t|| |d }qd S )Nr      r   )r   loadr   sortedshapenewaxisr   )r   fnfuncmatlab_masksr   arrnamer   r   r   r   r   strel_worker'   s    

zTestFootprints.strel_workerc           	      C   s   t t|}d}t|D ]}|| }||}|jdkrJ|d d t jf }t|jd d }t|||d d d d f  t||d d |d d f  t||d d d d |f  |d }qd S )Nr   r      r   )r   r   r   r   r    r!   intr   )	r   r"   r#   r$   r   r%   r   r   cr   r   r   strel_worker_3d2   s    
zTestFootprints.strel_worker_3dc                 C   s   |  dtj dS )zTest disk footprintsdata/disk-matlab-output.npzN)r&   r   diskr   r   r   r   test_footprint_diskC   s    z"TestFootprints.test_footprint_diskc                 C   s   |  dtj dS )zTest diamond footprintsdata/diamond-matlab-output.npzN)r&   r   diamondr-   r   r   r   test_footprint_diamondG   s    z%TestFootprints.test_footprint_diamondc                 C   s   |  dtj dS )zTest ball footprintsr+   N)r*   r   ballr-   r   r   r   test_footprint_ballK   s    z"TestFootprints.test_footprint_ballc                 C   s   |  dtj dS )zTest octahedron footprintsr/   N)r*   r   
octahedronr-   r   r   r   test_footprint_octahedronO   s    z(TestFootprints.test_footprint_octahedronc                 C   s   t j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d}tdd}t jg dg d	g dgt jd}td
d
}t|| t|| dS )zTest octagon footprints)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      )r   r   r   r   r   r   r   N)r   arrayr   r   octagonr   r   Zexpected_mask1Zactual_mask1Zexpected_mask2Zactual_mask2r   r   r   test_footprint_octagonT   s0    


z%TestFootprints.test_footprint_octagonc              	   C   s   t jg dg dg dg dg dg dg dgt jd}tdd}t jg dg dg dgt jd}tdd}t|| t|| t|tddj t|tddj dS )	zTest ellipse footprintsr6   r7   r   r   r8   r9   r   N)r   r:   r   r   ellipser   Tr<   r   r   r   test_footprint_ellipsej   s,    



z%TestFootprints.test_footprint_ellipsec                 C   s   t j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d}td}t jg dg dg dgt jd}td	}t|| t|| d
S )zTest star footprints)r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r      r9   r   N)r   r:   r   r   starr   r<   r   r   r   test_footprint_star~   s4    




z"TestFootprints.test_footprint_starN)__name__
__module____qualname__r   r   r   r&   r*   r.   r1   r3   r5   r=   r@   rC   r   r   r   r   r      s   r   z/function, args, supports_sequence_decomposition)r8   T)r8   rA   Fr	   c                    sN   | |d i}|j  ksJ |rJ| | dd}t fdd|D sJJ d S )Nr	   sequence)r	   decompositionc                    s   g | ]}|d  j  kqS )r   r   ).0Zfp_tupler   r   r   
<listcomp>       z(test_footprint_dtype.<locals>.<listcomp>)r	   all)functionargsZsupports_sequence_decompositionr	   Z	footprintrG   r   r   r   test_footprint_dtype   s
    rO   rM   r,   r2   radius)r   r'   r8   rA   r            	   
      2   K   d   c                 C   s   t t| }||dd d}||ddd}t|}|j|jks@J tt|t|t }|dkrv|dksJ n"| dkrdnd}||j	 |ksJ d S )	NFstrict_radiusrH   rG   r   r   r,   g?g333333?)
getattrr   footprint_from_sequencer    r   sumabsastyper(   size)rM   rP   fp_funcexpectedfootprint_sequenceapproximateerror	max_errorr   r   r   !test_nsphere_series_approximation   s    

 rh   )	r   r'   r8   rA   r   rU   rV   rW   rX   r[   c                 C   sv   t j}|| |d d}|| |dd}t |}|j|jks<J tt|t|t }d}||j	 |ksrJ d S )NrZ   crosses皙?)
r   r,   r]   r    r   r^   r_   r`   r(   ra   )rP   r[   rb   rc   rd   re   rf   rg   r   r   r   test_disk_crosses_approximation   s    
 rk   width)r8   rS   rV   rW   heightc                 C   sv   t j}|| |d d}|| |dd}t |}|j|jks<J tt|t|t }d}||j	 |ksrJ d S )N)rH   ri   rj   )
r   r>   r]   r    r   r^   r_   r`   r(   ra   )rl   rm   rb   rc   rd   re   rf   rg   r   r   r   "test_ellipse_crosses_approximation   s    
 rn   c                   C   s<   t t tjddd W d    n1 s.0    Y  d S Ni'  rG   )rP   rH   )pytestraises
ValueErrorr   r,   r   r   r   r   *test_disk_series_approximation_unavailable   s    rs   c                   C   s<   t t tjddd W d    n1 s.0    Y  d S ro   )rp   rq   rr   r   r2   r   r   r   r   *test_ball_series_approximation_unavailable   s    rt   )__doc__numpyr   rp   Znumpy.testingr   Zskimage._shared.testingr   Zskimage.morphologyr   r   markZparametrizer,   r2   r   r   r0   r4   r   r>   r;   rB   r   float64rO   rh   rk   rn   rs   rt   r   r   r   r   <module>   sD    	









