U
    ?h)                     @   s  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ddddddddddddd d!gd"d# Zejdddddddddd g	ejd$dd
gd%d& Zejd'ddddgejd(ddddg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   Z/var/www/html/venv/lib/python3.8/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   sp  t jdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddggt jd}tdd}t jdddgdddgdddggt jd}tdd}t|| t|| dS )zTest octagon footprintsr   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   s8  t jdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddgdddddddddddggt jd}tdd}t jdddgdddgdddggt jd}tdd}t|| t|| t|tddj t|tddj dS )zTest ellipse footprintsr   r   r   r   r6   N)r   r7   r   r   ellipser   Tr9   r   r   r   test_footprint_ellipsej   s,    

z%TestFootprints.test_footprint_ellipsec                 C   s  t jdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddgdddddddddddddggt jd}td}t jdddgdddgdddggt jd}td}t|| t|| dS )zTest star footprintsr   r   r      N)r   r7   r   r   starr   r9   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=   r@   r   r   r   r   r      s   r   z/function, args, supports_sequence_decomposition)r6   T)r6   r>   Fr	   c                    sN   | |d i}|j  kst|rJ| | dd}t fdd|D sJtd S )Nr	   sequence)r	   decompositionc                    s   g | ]}|d  j  kqS )r   r   ).0Zfp_tupler   r   r   
<listcomp>   s     z(test_footprint_dtype.<locals>.<listcomp>)r	   AssertionErrorall)functionargsZsupports_sequence_decompositionr	   Z	footprintrD   r   r   r   test_footprint_dtype   s
    rL   rJ   r,   r2   radiusr   r'   r6   r>   r            	   
      2   K   d   c                 C   s   t t| }||dd d}||ddd}t|}|j|jks@ttt|t	|t	 }|dkrv|dkstn"| dkrdnd}||j
 |kstd S )	NFstrict_radiusrE   rD   r   r   r,   g?g333333?)getattrr   footprint_from_sequencer    rH   r   sumabsastyper(   size)rJ   rM   fp_funcexpectedfootprint_sequenceapproximateerror	max_errorr   r   r   !test_nsphere_series_approximation   s    

 re   rX   c                 C   sv   t j}|| |d d}|| |dd}t |}|j|jks<ttt|t	|t	 }d}||j
 |ksrtd S )NrW   crosses皙?)r   r,   rZ   r    rH   r   r[   r\   r]   r(   r^   )rM   rX   r_   r`   ra   rb   rc   rd   r   r   r   test_disk_crosses_approximation   s    
 rh   widthheightc                 C   sv   t j}|| |d d}|| |dd}t |}|j|jks<ttt|t	|t	 }d}||j
 |ksrtd S )N)rE   rf   rg   )r   r;   rZ   r    rH   r   r[   r\   r]   r(   r^   )ri   rj   r_   r`   ra   rb   rc   rd   r   r   r   "test_ellipse_crosses_approximation   s    
 rk   c                	   C   s(   t t tjddd W 5 Q R X d S Ni'  rD   )rM   rE   )pytestraises
ValueErrorr   r,   r   r   r   r   *test_disk_series_approximation_unavailable   s    rp   c                	   C   s(   t t tjddd W 5 Q R X d S rl   )rm   rn   ro   r   r2   r   r   r   r   *test_ball_series_approximation_unavailable   s    rq   )__doc__numpyr   rm   Znumpy.testingr   Zskimage._shared.testingr   Zskimage.morphologyr   r   markZparametrizer,   r2   r   r   r0   r4   r   r;   r8   r?   r   Zfloat64rL   re   rh   rk   rp   rq   r   r   r   r   <module>   sH    	









"