o
    h)                     @   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   c/var/www/html/scripts/venv/lib/python3.10/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 ]!}|| }||}|jdkr%|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 ]O}|| }||}|jdkr%|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      |  dtj dS )zTest disk footprintsdata/disk-matlab-output.npzN)r&   r   diskr   r   r   r   test_footprint_diskC      z"TestFootprints.test_footprint_diskc                 C   r+   )zTest diamond footprintsdata/diamond-matlab-output.npzN)r&   r   diamondr.   r   r   r   test_footprint_diamondG   r0   z%TestFootprints.test_footprint_diamondc                 C   r+   )zTest ball footprintsr,   N)r*   r   ballr.   r   r   r   test_footprint_ballK   r0   z"TestFootprints.test_footprint_ballc                 C   r+   )zTest octahedron footprintsr1   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   expected_mask1actual_mask1expected_mask2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 footprintsr8   r9   r   r   r:   r;   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      r;   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/   r3   r5   r7   rC   rF   rI   r   r   r   r   r      s    r   z/function, args, supports_sequence_decomposition)r:   T)r:   rG   Fr	   c                    sR   | |d i}|j  ksJ |r%| | dd}t fdd|D s'J d S d S )Nr	   sequence)r	   decompositionc                    s   g | ]	}|d  j  kqS )r   r   ).0fp_tupler   r   r   
<listcomp>   s    z(test_footprint_dtype.<locals>.<listcomp>)r	   all)functionargssupports_sequence_decompositionr	   	footprintrM   r   r   r   test_footprint_dtype   s   rW   rS   r-   r4   radius)r   r'   r:   rG   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r<|dks:J d S | dkrBdnd}||j	 |ksMJ d S )	NFstrict_radiusrN   rM   r   r   r-   g?g333333?)
getattrr   footprint_from_sequencer    r   sumabsastyper(   size)rS   rX   fp_funcexpectedfootprint_sequenceapproximateerror	max_errorr   r   r   !test_nsphere_series_approximation   s   

 rp   )	r   r'   r:   rG   r   r]   r^   r_   r`   rc   c                 C   v   t j}|| |d d}|| |dd}t |}|j|jksJ tt|t|t }d}||j	 |ks9J d S )Nrb   crosses皙?)
r   r-   re   r    r   rf   rg   rh   r(   ri   )rX   rc   rj   rk   rl   rm   rn   ro   r   r   r   test_disk_crosses_approximation   s   
 rt   width)r:   r[   r^   r_   heightc                 C   rq   )N)rN   rr   rs   )
r   rD   re   r    r   rf   rg   rh   r(   ri   )ru   rv   rj   rk   rl   rm   rn   ro   r   r   r   "test_ellipse_crosses_approximation   s   
 rw   c                   C   >   t t tjddd W d    d S 1 sw   Y  d S Ni'  rM   )rX   rN   )pytestraises
ValueErrorr   r-   r   r   r   r   *test_disk_series_approximation_unavailable      "r}   c                   C   rx   ry   )rz   r{   r|   r   r4   r   r   r   r   *test_ball_series_approximation_unavailable   r~   r   )__doc__numpyr   rz   numpy.testingr   skimage._shared.testingr   skimage.morphologyr   r   markparametrizer-   r4   r   r   r2   r6   r   rD   r=   rH   r   float64rW   rp   rt   rw   r}   r   r   r   r   r   <module>   sF     	









