
    1-Ph-                     N   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          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                         Zej                            dddg          ej                            dg d          d                         Zej                            dg d          ej                            dddg          d                         Zej                            dg d          ej                            dg d          d                         Zd Zd Zej                            d edg          d!             Z ej                            d edg          ej                            d"ddg          d#                         Z! G 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                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )TestFootprintsc                    t          j        t          |                    }d}t          |          D ]K}||         } ||          }|j        dk    r|d d t           j        f         }t          ||           |dz   }Ld S )Nr      r   )nploadr   sortedshapenewaxisr   )selffnfuncmatlab_maskskarrnameexpected_maskactual_masks           h/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/morphology/tests/test_footprints.pystrel_workerzTestFootprints.strel_worker   s    wuRyy))l++ 	 	G(1M$q''K"d** -aaam <444AAA	 	    c           	         t          j        t          |                    }d}t          |          D ]}||         } ||          }|j        dk    r|d d t           j        f         }t          |j        d         dz            }t          |||d d d d f                    t          ||d d |d d f                    t          ||d d d d |f                    |dz   }d S )Nr   r      r   )r   r   r   r   r   r   intr   )	r   r   r   r   r   r   r   r   cs	            r   strel_worker_3dzTestFootprints.strel_worker_3d   s   wuRyy))l++ 	 	G(1M$q''K"d** -aaam < M'*Q.//AAqqq!!!G(<===AAAq!!!G(<===AAAqqq!G(<===AAA	 	r   c                 F    |                      dt          j                   dS )zTest disk footprintsdata/disk-matlab-output.npzN)r   r   diskr   s    r   test_footprint_diskz"TestFootprints.test_footprint_disk.   s!    7IIIIIr   c                 F    |                      dt          j                   dS )zTest diamond footprintsdata/diamond-matlab-output.npzN)r   r   diamondr&   s    r   test_footprint_diamondz%TestFootprints.test_footprint_diamond2   s"    :J<NOOOOOr   c                 F    |                      dt          j                   dS )zTest ball footprintsr$   N)r"   r   ballr&   s    r   test_footprint_ballz"TestFootprints.test_footprint_ball6   s!    :JOLLLLLr   c                 F    |                      dt          j                   dS )zTest octahedron footprintsr)   N)r"   r   
octahedronr&   s    r   test_footprint_octahedronz(TestFootprints.test_footprint_octahedron:   s"    =z?TUUUUUr   c                 n   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                  }t          j        dd          }t          j        g dg d	g dgt           j                  }t          j        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_mask2s        r   test_footprint_octagonz%TestFootprints.test_footprint_octagon>   s    111111111111111111111111111111111 (
 
 
  ")!Q//999iii"C28TTT!)!Q//^\222^\22222r   c           
         t          j        g dg dg dg dg dg dg dgt           j                  }t          j        dd          }t          j        g dg dg dgt           j                  }t          j        dd          }t          ||           t          ||           t          |t          j        dd          j                   t          |t          j        dd          j                   dS )	zTest ellipse footprintsr3   r4   r5   r7   r8   r9   r   N)r   r:   r;   r   ellipser   Tr=   s        r   test_footprint_ellipsez%TestFootprints.test_footprint_ellipseV   s   111111111111111111111 (
 
 
 ")!Q//999iii"C28TTT!)!Q//^\222^\222^Z%71%=%=%?@@@^Z%71%=%=%?@@@@@r   c                 v   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                  }t          j        d          }t          j        g dg dg dgt           j                  }t          j        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   r5      r9   r   N)r   r:   r;   r   starr   r=   s        r   test_footprint_starz"TestFootprints.test_footprint_starl   s   777777777777777777777777777777777777777 (!
 
 
$ "q))999iii"C28TTT!q))^\222^\22222r   N)__name__
__module____qualname__r   r"   r'   r+   r.   r1   rB   rF   rJ    r   r   r
   r
      s        	 	 	  "J J JP P PM M MV V V3 3 30A A A,3 3 3 3 3r   r
   z/function, args, supports_sequence_decompositionr8   T))r8   r7   r8   rH   Fr6   c                      | |di}|j         k    sJ |r& | |dd}t          fd|D                       sJ d S d S )Nr6   sequence)r6   decompositionc                 2    g | ]}|d          j         k    S )r   r5   ).0fp_tupler6   s     r   
<listcomp>z(test_footprint_dtype.<locals>.<listcomp>   s%    HHH8HQK%.HHHr   )r6   all)functionargssupports_sequence_decompositionr6   	footprintrR   s      `  r   test_footprint_dtyper]      s      $,e,,I?e####& J8TjIIIHHHHxHHHIIIIIJ JIIr   rY   r%   r-   radius)r   r   r8   rH   r7            	   
      2   K   d   c                    t          t          |           } ||dd           } ||dd          }t          j        |          }|j        |j        k    sJ t	          j        t	          j        |                    t                    |                    t                    z
                      }|dk    r
|dk    sJ d S | dk    rdnd}||j	        z  |k    sJ d S )	NFstrict_radiusrS   rR   r   r   r%   g?g333333?)
getattrr   r   r   r   sumabsastyper    size)rY   r^   fp_funcexpectedfootprint_sequenceapproximateerror	max_errors           r   !test_nsphere_series_approximationrv      s     j(++GwvU$GGGH uJWWW45GHHK.... F26(//#..1C1CC1H1HHIIJJE{{zzzzzz#v--CC4	x}$	111111r   )	r   r   r8   rH   r7   rc   rd   re   rf   rj   c                 x   t           j        } || |d           } || |d          }t          j        |          }|j        |j        k    sJ t	          j        t	          j        |                    t                    |                    t                    z
                      }d}||j	        z  |k    sJ d S )Nri   crosses皙?)
r   r%   r   r   r   rl   rm   rn   r    ro   )r^   rj   rp   rq   rr   rs   rt   ru   s           r   test_disk_crosses_approximationrz      s     oGwv]$OOOH m9   45GHHK.... F26(//#..1C1CC1H1HHIIJJEI8= I------r   width)r8   ra   rd   re   heightc                 x   t           j        } || |d           } || |d          }t          j        |          }|j        |j        k    sJ t	          j        t	          j        |                    t                    |                    t                    z
                      }d}||j	        z  |k    sJ d S )NrS   rx   ry   )
r   rD   r   r   r   rl   rm   rn   r    ro   )r{   r|   rp   rq   rr   rs   rt   ru   s           r   "test_ellipse_crosses_approximationr      s      GwufD999H iHHH45GHHK.... F26(//#..1C1CC1H1HHIIJJEI8= I------r   c                      t          j        t                    5  t          j        dd           d d d            d S # 1 swxY w Y   d S Ni'  rR   )r^   rS   )pytestraises
ValueErrorr   r%   rN   r   r   *test_disk_series_approximation_unavailabler          	z	"	" @ @uJ????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @   >AAc                      t          j        t                    5  t          j        dd           d d d            d S # 1 swxY w Y   d S r   )r   r   r   r   r-   rN   r   r   *test_ball_series_approximation_unavailabler      r   r   as_sequencec                    t          j        g dg dg dgt           j                  }t          j        g dg dg dgt           j                  }| , | |df|j        dfg          } | |df|j        dfg          }t	          j        |          }t          |          t          |          u sJ t          ||           d S )N)r   r   r   )r   r   r   )r   r   r   r5   r   r8   )r   r:   r;   rE   r   mirror_footprinttyper   )r   r\   expected_res
actual_ress       r   test_mirror_footprintr      s    )))YYY			:BHEEI8YYY			999=RXNNNLK)Q)+q1A BCC	"{\1$57J#KLL,Y77Jj!1!11111z*****r   pad_endc                    t          j        ddgddgddggt           j                  }|du rddgnddg}t          j        ||          }| , | |df|j        dfg          } | |df|j        dfg          }t          j        ||	          }t          |          t          |          u sJ t          ||           d S )
Nr   r   T)r   r   )r   r   )r   r   r   r8   )r   )	r   r:   r;   padrE   r   pad_footprintr   r   )r   r   r\   	pad_widthr   r   s         r   test_pad_footprintr      s     1a&1a&1a&128<<I$+tOO  &&9II6)Y//LK)Q)+q1A BCC	"{\1$57J#KLL))WEEEJj!1!11111z*****r   c                   V   e Zd Zej                            dg d          ej                            dg d          d                         Zej                            dg d          ej                            dg d          ej                            dg d          d                                     Zej                            dg d          ej                            d	d
dg          d                         Zej                            dddg          d             Z	dS )Test_footprint_rectangulei)r   r   r   r8   rH   jc                 x    t          j        ||fd          }t          ||f          }t          ||           d S Nr;   r5   r   onesr   r   )r   r   r   desiredactuals        r   test_rectanglez(Test_footprint_rectangule.test_rectangle   sC     '1a&000$aV,,VW%%%%%r   r   c                 |    t          j        |||fd          }t          |||f          }t          ||           d S r   r   )r   r   r   r   r   r   s         r   test_cuboidz%Test_footprint_rectangule.test_cuboid  sG     '1a)7333$aAY//VW%%%%%r   r   )rO   )r7   r7   )r7   r7   r`   rS   	separablerR   c                     t          |          }t          ||          }t          |          }t          ||           d S )Nr~   )r   r   r   )r   r   rS   regular
decomposed
recomposeds         r   test_decompositionz,Test_footprint_rectangule.test_decomposition	  sF     &e,,(mLLL
,Z88
Z)))))r   )r   rP   c                     t          |d          }d}t          j        t          |          5 }t          |d          }ddd           n# 1 swxY w Y   t	          |           t          ||           dS )zHShould fall back to decomposition="separable" for uneven footprint size.r   r~   z@decomposition='sequence' is only supported for uneven footprints)matchrR   N)r   r   warnsUserWarningr   r   )r   r   r   regexrecordr   s         r   *test_uneven_sequence_decomposition_warningzDTest_footprint_rectangule.test_uneven_sequence_decomposition_warning  s     &e;GGGR\+U333 	Jv(jIIIF	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J&!!!VW%%%%%s   AAAN)
rK   rL   rM   r   markparametrizer   r   r   r   rN   r   r   r   r      sd       [S///22[S///22& & 32 32&
 [S///22[S///22[S///22& & 32 32 32&
 [W&?&?&?@@[_{J.GHH* * IH A@* [WtVn55& & 65& & &r   r   )#__doc__numpyr   r   numpy.testingr   skimage._shared.testingr   r   skimage.morphologyr   r   r   r
   r   r   r%   r-   r*   r0   rD   r<   rI   r;   float64r]   rv   rz   r   r   r   tupler   r   r   rN   r   r   <module>r      sM         & & & & & & < < < < < < < < ) ) ) ) ) ) K K K K K K K Ks3 s3 s3 s3 s3 s3 s3 s3l 5	$%	$%		T4(		d+	i.		VU+		VT*	$&	  28RZ"899J J :9 J ff%566#S#S#STT2 2 UT 762  #B#B#BCC5$-88. . 98 DC. ...11>>>22
. 
. 32 21
.@ @ @@ @ @ 66	+ 	+ 76	+ 66T5M22
+ 
+ 32 76
+ &  &  &  &  &  &  &  &  &  &r   