
    a6d",                     L   d dl Zd dlZd dlmZmZ d dlmZ d dl	m
Z
mZmZ d dlmZ d dlmZmZmZ  ej         e
j                              Zedk    Zd Zd	 Zd
 Zd Zd Zd-dZej                            dg d          ej                            dd          ej                            dddg          d                                     Zej                            dg d          ej                            dd          ej                            dd          ej                            dddg          d                                                 Z ej                            dg d          ej                            dd          ej                            dd          ej                            ddg          d                                                 Z!ej                            dg d          ej                            dd          ej                            ddg          d                                      Z"ej                            dg d          ej                            dd!          ej                            dddg          d"                                     Z#ej                            dg d          ej                            dd#          ej                            ddg          d$                                     Z$d% Z%d& Z&ej'        ej(        ej)        ej*        gZ+ej                            de+          d'             Z,d( Z-ej)        ej*        gZ.ej                            de.          d)             Z/d* Z0d+ Z1d, Z2dS ).    N)assert_array_equalassert_equal)ndimage)datacolor
morphology)img_as_bool)binary
footprintsgrayg?c                      t          j        d          } t          j        t          d dd df         |           }t          t          j        t          d dd df         |                     }t          ||           d S )N   d      	r   squarer
   binary_erosionbw_imgr	   r   erosionr   	footprint
binary_resgray_ress      Dlib/python3.11/site-packages/skimage/morphology/tests/test_binary.pytest_non_square_imager      su    !!$$I&vdsdDSDj'99EEJ4<ttTcTz(:IFFGGHz8,,,,,    c                      t          j        d          } t          j        t          |           }t          t          j        t          |                     }t          ||           d S Nr   r   r   s      r   test_binary_erosionr      S    !!$$I&vy99J4<	::;;Hz8,,,,,r   c                      t          j        d          } t          j        t          |           }t          t          j        t          |                     }t          ||           d S r   )	r   r   r
   binary_dilationr   r	   r   dilationr   r   s      r   test_binary_dilationr$      sS    !!$$I'	::J4=;;<<Hz8,,,,,r   c                      t          j        d          } t          j        t          |           }t          t          j        t          |                     }t          ||           d S r   )	r   r   r
   binary_closingr   r	   r   closingr   r   s      r   test_binary_closingr(   $   r    r   c                      t          j        d          } t          j        t          |           }t          t          j        t          |                     }t          ||           d S r   )	r   r   r
   binary_openingr   r	   r   openingr   r   s      r   test_binary_openingr,   +   r    r      c                     | dk    r)t          j        d|z  t           j                  }d|d<   nF| dk    r)t          j        d|z  t           j                  }d|d<   nt	          j        d|d	          }|S )
Nr   )   dtyper   )   r2   r"          )n_dimseed)nponesuint8zerosr   binary_blobs)functionndimimgs      r   _get_decomp_test_datar?   2   s    ###gftm28444D			&	&	&hv}BH555D		$Q777Jr   r<   )r   r"   r&   r*   size)r         decomposition	separablesequencec                     t          j        |d          }t          j        ||          }t          |           }t          t          |           } |||          } |||          }t          ||           dS tValidate footprint decomposition for various shapes.

    comparison is made to the case without decomposition.
    NrC   r   )r   r   r?   getattrr
   r   	r<   r@   rC   footprint_ndarrayr   r>   funcexpectedouts	            r   test_square_decompositionrQ   >   s     #)$dCCC!$mDDDI

)
)C68$$DtC#4555H
$si
(
(
(Cx%%%%%r   nrowsncolsc                     t          j        ||d          }t          j        |||          }t          |           }t          t          |           } |||          } |||          }	t          ||	           dS rG   )r   	rectangler?   rK   r
   r   )
r<   rR   rS   rC   rM   r   r>   rN   rO   rP   s
             r   test_rectangle_decompositionrV   R   s     #,UENNN$UEOOOI

)
)C68$$DtC#4555H
$si
(
(
(Cx%%%%%r   m)r   r3   r-   r   rA      nc                    |dk    rQ|dk    rKt          j        t                    5  t          j        |||           ddd           dS # 1 swxY w Y   dS t          j        ||d          }t          j        |||          }t          |           }t          t          |           } |||          } |||          }	t          ||	           dS )rH   r   rI   NrJ   )	pytestraises
ValueErrorr   octagonr?   rK   r
   r   )
r<   rW   rY   rC   rM   r   r>   rN   rO   rP   s
             r   test_octagon_decompositionr_   g   sA    	Avv!q&&]:&& 	B 	Bq!=AAAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B '.q!4HHH&q!=III	#H--vx((4'8999d3),,,8S)))))s   AAAradius)r3   r-   rX   c                     t          j        |d          }t          j        ||          }t          |           }t          t          |           } |||          } |||          }t          ||           dS rG   )r   diamondr?   rK   r
   r   	r<   r`   rC   rM   r   r>   rN   rO   rP   s	            r   test_diamond_decompositionrd      s     #*6FFF"6GGGI

)
)C68$$DtC#4555H
$si
(
(
(Cx%%%%%r   )r   rA   rX   c                     t          j        |d          }t          j        ||          }t          | d          }t          t          |           } |||          } |||          }t          ||           dS rH   NrI   r   )r=   rJ   )r   cuber?   rK   r
   r   rL   s	            r   test_cube_decompositionrh      s     #DAAAMBBBI
q
1
1
1C68$$DtC#4555H
$si
(
(
(Cx%%%%%r   )r3   r-   r   c                     t          j        |d          }t          j        ||          }t          | d          }t          t          |           } |||          } |||          }t          ||           dS rf   )r   
octahedronr?   rK   r
   r   rc   s	            r   test_octahedron_decompositionrk      s     #-fDIII%fMJJJI
q
1
1
1C68$$DtC#4555H
$si
(
(
(Cx%%%%%r   c                      t          j        dt           j                  } t          j        dt                    }d|ddddf<   t          j        ||           }t          t          j	        ||                     }t          ||           d S )N)r/   r/   r0   )   rm   Tr-      )r7   r8   r9   r:   boolr
   r   r	   r   r   r   )r   r>   r   r   s       r   test_footprint_overflowrp      s    111I
(84
(
(
(CC"ad
O&sI66J4<Y7788Hz8,,,,,r   c                  x   t           j        t           j        fD ]} t          j        dt          j                  }t          j        d          }t          j        |          }|                                } | |||           t          j        ||k              sJ t          | | ||                     d S )N)r   r   r0   )
   rr   rP   )
r
   r   r"   r7   r8   r9   
zeros_likecopyanyr   )rN   r   r>   rP   	out_saveds        r   test_out_argumentrx      s    &(>? 6 6GF"(333	ghmC  HHJJ	S)%%%%vcY&'''''3S) 4 455556 6r   c                 
   t          j        d          }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          ||           d S )Nr3   )r`   )
r   r   r   r   r   r   r   r   r   r   )
r   r   r3   r3   r3   r3   r3   r3   r   r   )
r   r   r3   r3   r3   r   r   r3   r   r   )r   rb   r7   arrayr9   r   )r<   r   imageim_expectedim_tests        r   test_default_footprintr~      s    "!,,,IH4444444444444444444444444444444444444446 8:xA AE (5),,KhuooG{G,,,,,r   c                     t          j        dt                    } d| ddddddf<   t          j        |           }t          j        dt                    }t          j        dd          |ddddddf<   t          ||           d S )N   r   r   r3   r-   r0   r   rX   )r7   r:   ro   r
   r*   ndigenerate_binary_structurer   )r{   openedimage_expecteds      r   "test_3d_fallback_default_footprintr      s    HY%%EE!B$"ad
"5))F Xit444N$'$A!Q$G$GN1Q3!QqS=!v~.....r   c                     t          j        dt                    }d|ddddddf<   t          j        dt           j                  } | ||          }t          ||           d S )Nr   r3   r-   r   )r   r   r   r0   )r7   r:   ro   r8   r9   r   )r<   r{   rg   	new_images       r   test_3d_fallback_cube_footprintr      so     HY%%EE!B$"ad
79BH---D%%Iy%(((((r   c                     t          j        dt           j                  } d| ddddf<   d| ddddf<   d| d	<   t          j        |           }t          j        |           }t          j        dd
          }t          j        | |          }t          j        | |          }t          ||           t          ||           d S )N	   r    @  r-   r      r     rA   rA   r3   )	structure)	r7   r:   uint16r
   r*   r&   r   r   r   )r{   
bin_opened
bin_closedr   ndimage_openedndimage_closeds         r   test_2d_ndimage_equivalencer     s    HVRY''EE!B$"*E!B$"*E$K&u--J&u--J-a33I'CCCN'CCCNz>222z>22222r   c                     t          j        dt           j                  } d| ddddf<   d| ddddf<   d| d	<   t          j        |           }t          j        |           }t          j        | t           j        
          }t          j        | t           j        
          }t          j        | |           t          j        | |           t          |j	        t                     t          |j	        t                     t          |j	        t           j                   t          |j	        t           j                   d S )Nr   r   r-   r   r   r   r   r   r   r0   rs   r7   r:   r   r
   r*   r&   
empty_liker9   r   r1   ro   r{   r   r   
int_opened
int_closeds        r   test_binary_output_2dr     s   HVRY''EE!B$"*E!B$"*E$K&u--J&u--JuBH555JuBH555J
%Z0000
%Z0000!4(((!4(((!28,,,!28,,,,,r   c                     t          j        dt           j                  } d| ddddddf<   d| ddddddf<   d| d	<   t          j        |           }t          j        |           }t          j        | t           j        
          }t          j        | t           j        
          }t          j        | |           t          j        | |           t          |j	        t                     t          |j	        t                     t          |j	        t           j                   t          |j	        t           j                   d S )N)r   r   r   r   r-   r   r   r   r   r   )rA   rA   rA   r0   rs   r   r   s        r   test_binary_output_3dr   +  s&   HY	**E#E!B$"ad
#E!B$"ad
E'N&u--J&u--JuBH555JuBH555J
%Z0000
%Z0000!4(((!4(((!28,,,!28,,,,,r   )r-   )3numpyr7   r[   numpy.testingr   r   scipyr   r   skimager   r   r   skimage.utilr	   skimage.morphologyr
   r   r   rgb2gray	astronautr>   r   r   r   r$   r(   r,   r?   markparametrizerQ   rV   r_   rd   rh   rk   rp   rx   r   r"   r*   r&   binary_functionsr~   r   binary_3d_fallback_functionsr   r   r   r    r   r   <module>r      s3        : : : : : : : :             + + + + + + + + + + $ $ $ $ $ $ 7 7 7 7 7 7 7 7 7 7 en^T^%%&&	z	- - -- - -- - -- - -- - -	 	 	 	 MMM  ,,;
*CDD& & ED -,	 & MMM  *--*--;
*CDD& & ED .- .-	 & MMM  011011:,77* * 87 21 21	 *$ MMM  9--:,77& & 87 .-	 & MMM  ++;
*CDD& & ED ,+	 & MMM  9--:,77& & 87 .-	 &- - -6 6 6 )6+A)6+@B  %566- - 76-(
/ 
/ 
/ !' 5v7LM  %ABB) ) CB)3 3 3"- - -*- - - - -r   