o
    j-                     @   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   i/var/www/html/Deteccion_Ine/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   Zexpected_mask1Zactual_mask1Zexpected_mask2Z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+   r7   r:   r=   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.   ).0Zfp_tupler.   r   r   
<listcomp>   s    z(test_footprint_dtype.<locals>.<listcomp>)r/   all)functionargsZsupports_sequence_decompositionr/   	footprintrC   r   r.   r   test_footprint_dtype   s   rK   rH   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_radiusrD   rC   r
   r   r!   g?g333333?)
getattrr   r   r   r   sumabsastyper   size)rH   rL   fp_funcexpectedfootprint_sequenceapproximateerror	max_errorr   r   r   !test_nsphere_series_approximation   s   

 rc   )	r
   r   r1   r;   r0   rQ   rR   rS   rT   rW   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 )NrV   crosses皙?)
r   r!   r   r   r   rY   rZ   r[   r   r\   )rL   rW   r]   r^   r_   r`   ra   rb   r   r   r   test_disk_crosses_approximation   s   
 rg   width)r1   rO   rR   rS   heightc                 C   rd   )NrD   re   rf   )
r   r8   r   r   r   rY   rZ   r[   r   r\   )rh   ri   r]   r^   r_   r`   ra   rb   r   r   r   "test_ellipse_crosses_approximation   s   
 rk   c                   C   >   t t tjddd W d    d S 1 sw   Y  d S Ni'  rC   )rL   rD   )pytestraises
ValueErrorr   r!   r   r   r   r   *test_disk_series_approximation_unavailable      "rq   c                   C   rl   rm   )rn   ro   rp   r   r(   r   r   r   r   *test_ball_series_approximation_unavailable   rr   rs   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   r9   r   Zmirror_footprinttyper   )rt   rJ   expected_res
actual_resr   r   r   test_mirror_footprint   s    "
rx   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   )ry   )	r   r3   r4   padr9   r   Zpad_footprintru   r   )rt   ry   rJ   Z	pad_widthrv   rw   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   Z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   )rA   )r0   r0   )r0   r0   rN   rD   	separablerC   c                 C   s*   t |}t ||d}t|}t|| d S )Nrj   )r   r   r   )r   r   rD   ZregularZ
decomposedZ
recomposedr   r   r   test_decomposition	  s   z,Test_footprint_rectangule.test_decomposition)r   rB   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   rj   z@decomposition='sequence' is only supported for uneven footprints)matchrC   N)r   rn   Z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)
r>   r?   r@   rn   markparametrizer   r   r   r   r   r   r   r   r|      s    r|   )#__doc__numpyr   rn   Znumpy.testingr   Zskimage._shared.testingr   r   Zskimage.morphologyr   r   r   r   r   r   r!   r(   r&   r*   r8   r5   r<   r4   Zfloat64rK   rc   rg   rk   rq   rs   tuplerx   r{   r|   r   r   r   r   <module>   sN    v








