o
    ci-                     @   s  d Z ddlZddlZddlmZ ddlmZmZ ddl	m
Z
 ddl	mZ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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ejd&edgd'd( Z ejd&edgejd)ddgd*d+ Z!G d,d- d-Z"dS ).zX
Tests for Morphological footprints
(skimage.morphology.footprint)

Author: Damian Eads
    N)assert_equal)fetchassert_stacklevel)
footprints)footprint_rectanglefootprint_from_sequencec                   @   sT   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S )TestFootprintsc                 C   sb   t t|}d}t|D ]!}|| }||}|jdkr%|d d t jf }t|| |d }qd S )Nr      r
   )nploadr   sortedshapenewaxisr   )selffnfuncmatlab_maskskarrnameexpected_maskactual_mask r   r/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/skimage/morphology/tests/test_footprints.py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_3d   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_disk.      z"TestFootprints.test_footprint_diskc                 C   r   )zTest diamond footprintsdata/diamond-matlab-output.npzN)r   r   diamondr"   r   r   r   test_footprint_diamond2   r$   z%TestFootprints.test_footprint_diamondc                 C   r   )zTest ball footprintsr    N)r   r   ballr"   r   r   r   test_footprint_ball6   r$   z"TestFootprints.test_footprint_ballc                 C   r   )zTest octahedron footprintsr%   N)r   r   
octahedronr"   r   r   r   test_footprint_octahedron:   r$   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
   dtype      )r   r
   r   r
   r
   r
   r
   N)r   arrayuint8r   octagonr   r   expected_mask1actual_mask1expected_mask2actual_mask2r   r   r   test_footprint_octagon>   s(   "
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 footprintsr,   r-   r.   r0   r1   r2   r
   N)r   r3   r4   r   ellipser   Tr6   r   r   r   test_footprint_ellipseV   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.      r2   r
   N)r   r3   r4   r   starr   r6   r   r   r   test_footprint_starl   s,   
"

z"TestFootprints.test_footprint_starN)__name__
__module____qualname__r   r   r#   r'   r)   r+   r;   r>   rA   r   r   r   r   r      s    r   z/function, args, supports_sequence_decompositionr1   T))r1   r0   r1   r?   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/   	footprintrG   r   r.   r   test_footprint_dtype   s   rQ   rM   r!   r(   radius)r
   r   r1   r?   r0            	   
      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_radiusrH   rG   r
   r   r!   g?g333333?)
getattrr   r   r   r   sumabsastyper   size)rM   rR   fp_funcexpectedfootprint_sequenceapproximateerror	max_errorr   r   r   !test_nsphere_series_approximation   s   

 ri   )	r
   r   r1   r?   r0   rW   rX   rY   rZ   r]   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 )Nr\   crosses皙?)
r   r!   r   r   r   r_   r`   ra   r   rb   )rR   r]   rc   rd   re   rf   rg   rh   r   r   r   test_disk_crosses_approximation   s   
 rm   width)r1   rU   rX   rY   heightc                 C   rj   )NrH   rk   rl   )
r   r<   r   r   r   r_   r`   ra   r   rb   )rn   ro   rc   rd   re   rf   rg   rh   r   r   r   "test_ellipse_crosses_approximation   s   
 rq   c                   C   >   t t tjddd W d    d S 1 sw   Y  d S Ni'  rG   )rR   rH   )pytestraises
ValueErrorr   r!   r   r   r   r   *test_disk_series_approximation_unavailable      "rw   c                   C   rr   rs   )rt   ru   rv   r   r(   r   r   r   r   *test_ball_series_approximation_unavailable   rx   ry   as_sequencec                 C   s   t g dg dg dgt j}t jg dg dg dgt jd}| d ur;| |df|jdfg}| |df|jdfg}t|}t|t|u sJJ t|| d S )N)r   r   r   )r   r
   r
   )r
   r
   r   r.   r   r1   )r   r3   r4   r=   r   mirror_footprinttyper   )rz   rP   expected_res
actual_resr   r   r   test_mirror_footprint   s    "
r   pad_endc                 C   s   t ddgddgddggt j}|du rddgnddg}t ||}| d ur<| |df|jdfg}| |df|jdfg}tj||d	}t|t|u sMJ t|| d S )
Nr   r
   T)r   r   )r   r
   )r
   r   r   r1   )r   )	r   r3   r4   padr=   r   pad_footprintr|   r   )rz   r   rP   	pad_widthr}   r~   r   r   r   test_pad_footprint   s    r   c                   @   s   e Zd Zejdg dejdg ddd Zejdg dejdg d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	ddgdd Z	dS )Test_footprint_rectangulei)r   r
   r   r1   r?   jc                 C   s,   t j||fdd}t||f}t|| d S Nr4   r.   r   onesr   r   )r   r   r   desiredactualr   r   r   test_rectangle   s   z(Test_footprint_rectangule.test_rectangler   c                 C   s0   t j|||fdd}t|||f}t|| d S r   r   )r   r   r   r   r   r   r   r   r   test_cuboid  s   z%Test_footprint_rectangule.test_cuboidr   )rE   )r0   r0   )r0   r0   rT   rH   	separablerG   c                 C   s*   t |}t ||d}t|}t|| d S )Nrp   )r   r   r   )r   r   rH   regular
decomposed
recomposedr   r   r   test_decomposition	  s   z,Test_footprint_rectangule.test_decomposition)r   rF   c                 C   s`   t |dd}d}tjt|d}t |dd}W d   n1 s w   Y  t| t|| dS )zHShould fall back to decomposition="separable" for uneven footprint size.r   rp   z@decomposition='sequence' is only supported for uneven footprints)matchrG   N)r   rt   warnsUserWarningr   r   )r   r   r   regexrecordr   r   r   r   *test_uneven_sequence_decomposition_warning  s   zDTest_footprint_rectangule.test_uneven_sequence_decomposition_warningN)
rB   rC   rD   rt   markparametrizer   r   r   r   r   r   r   r   r      s    r   )#__doc__numpyr   rt   numpy.testingr   skimage._shared.testingr   r   skimage.morphologyr   r   r   r   r   r   r!   r(   r&   r*   r<   r5   r@   r4   float64rQ   ri   rm   rq   rw   ry   tupler   r   r   r   r   r   r   <module>   sN    v








