
    a6d                     t    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	m
Z
 d dlmZ  G d de j                  ZdS )    N)assert_equal)binary_dilationbinary_erosion)datafeature)img_as_floatc                   J    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )	TestCannyc           
          t          j        t          j        d          dddt          j        dt
                              }|                     t          j        |                     dS )z<Test that the Canny filter finds no points for a blank field   r      r   N)r   cannynpzerosonesboolassertFalseanyselfresults     @lib/python3.11/site-packages/skimage/feature/tests/test_canny.pytest_00_00_zeroszTestCanny.test_00_00_zeros
   sZ    rx111aBGH#=% =% & &(((((    c           
          t          j        t          j                            d          dddt          j        dt                              }|                     t          j        |                     dS )z<Test that the Canny filter finds no points in a masked imager   sizer   r   N)	r   r   r   randomuniformr   r   r   r   r   s     r   test_00_01_zeros_maskzTestCanny.test_00_01_zeros_mask   s_    -	 1 1x 1 @ @!Q "4 8 8: :(((((r   c           
         t           j        ddddf                             t                    dz  \  }}t          j        t          j        ||z  ||z  z             dz
            dk     }t          j        |                    t                    dddt          j        |j	        t                              }t          |d          }t          |d          }t          j        |t          j        |                    }|                     t          j        ||                              t          j        |          }|                     |d	k               |                     |d
k                dS )z9Test that the Canny filter finds the outlines of a circle8         ?{Gz?r   r      
iterations  @  N)r   mgridastypefloatabssqrtr   r   r   shaper   r   r   logical_andlogical_not
assertTrueallsum)	r   ijcr   cdcecdepoint_counts	            r   test_01_01_circlezTestCanny.test_01_01_circle   s4   xS$s(*+22599C?1F271q51q5=))B.//#5qxx1a$9O9OPP
 Q1---A!,,,nR!3!344s6{++,,, fVnnd*+++d*+++++r   c           
         t           j                            d           t           j        ddddf                             t
                    dz  \  }}t          j        t          j        ||z  ||z  z             dz
            dk     }|                    t
                    dz  t           j                            |j	                  dz  z   }t          j        |ddd	t          j        |j	        t                              }t          |d
          }t          |d
          }t          j        |t          j        |                    }|                     t          j        ||                              t          j        |          }	|                     |	dk               |                     |	dk                dS )zNTest that the Canny filter finds the circle outlines
         in a noisy imager   r#   r$   r%   r&   r   r   皙?皙?r(   r*   r+   N)r   r   seedr,   r-   r.   r/   r0   r    r1   r   r   r   r   r   r   r2   r3   r4   r5   r6   )
r   r7   r8   r9   cfr   r:   r;   r<   r=   s
             r   test_01_02_circle_with_noisez&TestCanny.test_01_02_circle_with_noise-   sq    		qxS$s(*+22599C?1F271q51q5=))B.//#5XXe__r!BI$5$517$5$C$Cb$HHr1b"bgagt.D.DEE
 Q1---A!,,,nR!3!344s6{++,,,fVnnd*+++d*+++++r   c                 |    |                      t          t          j        t	          j        d          ddd           d S )N)r   r   r   r   r   )assertRaises
ValueErrorr   r   r   r   )r   s    r   test_image_shapezTestCanny.test_image_shapeA   s=    *gmRXl5K5KQQ	  	  	  	  	 r   c           
      2   t          j        t          j        d          dddt          j        dt
                              }t          j        t          j        d          ddd          }|                     t          j        ||k                         d S )Nr   r   r   )r   r   r   r   r   r   r4   r5   )r   result1result2s      r   test_mask_nonezTestCanny.test_mask_noneE   s~    - 2 2Aq!RWX $>& >& ' '- 2 2Aq!<<w'12233333r   c           	          t          t          j                    d d dd d df                   }t          j        g dg dg dg dg dg dg          }t          j        |ddd	          }t          ||           d S )
Nd   )FFFFFF)FTTTFF)FFFTFF)FFTTFFg333333?g?T)low_thresholdhigh_thresholduse_quantiles)r   r   camerar   arrayr   r   r   )r   imagecorrect_outputr   s       r   test_use_quantileszTestCanny.test_use_quantilesK   s    T[]]55S5%%C%<899 7777777777777777779: : uC-13 3 3 	V^,,,,,r   c                     t          j        d          }t          j        t          j        |          dk              sJ d S )N)
   rX   r   )r   r   r5   r   r   r   rT   s     r   test_img_all_oneszTestCanny.test_img_all_ones]   s<    !!vgmE**a/0000000r   c                 ,   t          t          j                    d d dd d df                   }|                     t          t
          j        |ddd           |                     t          t
          j        |ddd           |                     t          t
          j        |ddd           |                     t          t
          j        |ddd	           t          j                    }|                     t          t
          j        |ddd
           d S )N2   Tr%   g@)rQ   rO   rP   c   g?i   )r   r   rR   rF   rG   r   r   rY   s     r   test_invalid_use_quantilesz$TestCanny.test_invalid_use_quantilesa   s4   T[]]44R42:677*gmU$(+C 	 	A 	A 	A 	*gmU$(*3 	 	@ 	@ 	@ 	*gmU$(*3 	 	@ 	@ 	@ 	*gmU$(+D 	 	B 	B 	B *gmU$(*3 	 	@ 	@ 	@ 	@ 	@r   c           
      B   t          j                    }t          |          }t          j        |          }t          j        |          }t          ||           d}d}t          t          j        |d||          t          j        |dd|z  d|z                       dS )zACheck that the same output is produced regardless of image dtype.r@   rA   g      ?   N)r   rR   r   r   r   r   )r   image_uint8image_floatresult_uint8result_floatlowhighs          r   
test_dtypezTestCanny.test_dtypeu   s    kmm";//}[11}[11\<000W];S$??];S3Yd
KK	M 	M 	M 	M 	Mr   N)__name__
__module____qualname__r   r!   r>   rD   rH   rL   rV   rZ   r`   ri    r   r   r
   r
   	   s        ) ) )) ) ), , ,., , ,(     4 4 4- - -$1 1 1@ @ @(M M M M Mr   r
   )unittestnumpyr   skimage._shared.testingr   scipy.ndimager   r   skimager   r   skimage.utilr   TestCaser
   rm   r   r   <module>ru      s         0 0 0 0 0 0 9 9 9 9 9 9 9 9 ! ! ! ! ! ! ! ! % % % % % %zM zM zM zM zM! zM zM zM zM zMr   