
    hh                     ~    d dl 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
mZ d dlmZ  G d de j                        Zy)    N)assert_equal)binary_dilationbinary_erosion)datafeature)img_as_floatc                   T    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 Zd Zy)	TestCannyc           
          t        j                  t        j                  d      dddt        j                  dt
                    }| j                  t        j                  |             y)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     ^/var/www/html/dev/engine/venv/lib/python3.12/site-packages/skimage/feature/tests/test_canny.pytest_00_00_zeroszTestCanny.test_00_00_zeros   sB    rxx11aBGGHd<ST(    c           
          t        j                  t        j                  j	                  d      dddt        j
                  dt                    }| j                  t        j                  |             y)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   sP    II8,aArxx$7O
 	(r   c           
         t         j                  ddddf   j                  t              dz  \  }}t        j                  t        j
                  ||z  ||z  z         dz
        dk  }t        j                  |j                  t              dddt        j                  |j                  t                    }t        |d      }t        |d      }t        j                  |t        j                  |            }| j                  t        j                   ||                t        j"                  |      }| j                  |d	kD         | j                  |d
k         y)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   s   xxS$s(*+2259C?1FF2771q51q5=)C/047qxx1a$9OP
 Q1-A!,nnR!34s6{+, ffVnd*+d*+r   c           
      d   t         j                  j                  d       t         j                  ddddf   j	                  t
              dz  \  }}t        j                  t        j                  ||z  ||z  z         dz
        dk  }|j	                  t
              dz  t         j                  j                  |j                        dz  z   }t        j                  |ddd	t        j                  |j                  t                    }t        |d
      }t        |d
      }t        j                   |t        j"                  |            }| j%                  t        j&                  ||                t        j(                  |      }	| j%                  |	dkD         | j%                  |	dk         y)zMTest 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.   sB    			qxxS$s(*+2259C?1FF2771q51q5=)C/047XXe_s"RYY%6%6AGG%6%Ds%JJr1c30FG
 Q1-A!,nnR!34s6{+,ffVnd*+d*+r   c                 z    | j                  t        t        j                  t	        j
                  d      ddd       y )N)r   r   r   r   r   )assertRaises
ValueErrorr   r   r   r   )r   s    r   test_image_shapezTestCanny.test_image_shapeB   s)    *gmmRXXl5KQPQSTUr   c           
      0   t        j                  t        j                  d      dddt        j                  dt
                    }t        j                  t        j                  d      ddd      }| j                  t        j                  ||k(               y )Nr   r   r   )r   r   r   r   r   r   r4   r5   )r   result1result2s      r   test_mask_nonezTestCanny.test_mask_noneE   sc    -- 2Aq!RWWXt=TU-- 2Aq!<w'12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        ||       y )
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_quantilesJ   so    T[[]5S5%C%<89 :7998:	
 S
 	V^,r   c                     t        j                  d      }t        j                  t        j                  |      dk(        sJ y )N
   rY   r   )r   r   r5   r   r   r   rT   s     r   test_img_all_oneszTestCanny.test_img_all_ones`   s0    !vvgmmE*a/000r   c                    t        t        j                         d d dd d df         }| j                  t        t
        j                  |ddd       | j                  t        t
        j                  |ddd       | j                  t        t
        j                  |ddd       | j                  t        t
        j                  |ddd	       t        j                         }| j                  t        t
        j                  |ddd
       y )N2   Tr%   g@)rQ   rO   rP   c   g?i   )r   r   rR   rF   rG   r   r   rZ   s     r   test_invalid_use_quantilesz$TestCanny.test_invalid_use_quantilesd   s   T[[]4R42:67MM 	 	
 	MM 	 	
 	MM 	 	
 	MM 	 	
 MM 	 	
r   c           
      2   t        j                         }t        |      }t        j                  |      }t        j                  |      }t        ||       d}d}t        t        j                  |d||      t        j                  |dd|z  d|z               y)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_dtype   s{    kkm";/}}[1}}[1\<0MM+sC6MM+sC#IsTzB	
r   c                     t        j                         }dD ]R  }t        t        j                  ||      t        j                  ||t        j                  |t                           T y)zAThe masked and unmasked algorithms should return the same result.)constantnearestreflect)modedtype)ro   maskN)r   rR   r   r   r   r   	ones_liker   )r   rT   ro   s      r   test_full_mask_matches_no_maskz(TestCanny.test_full_mask_matches_no_mask   sM    6 	De$/e$R\\%t5TU	r   c                 J   t         j                  t         j                  fD ]t  }t        j                  d|      }t        j                  |      j
                  |d<   t        j                  t        d      5  t        j                  |       d d d        v y # 1 sw Y   xY w)NrX   rp   )r'   r'   z'64-bit integer images are not supported)match)r   int64uint64r   iinfomaxpytestraisesrG   r   r   )r   rq   rT   s      r   test_unsupported_int64z TestCanny.test_unsupported_int64   s    hh		* 	%EHHXU3E((5/--E$K"K % e$% %	%% %s   8BB"	N)__name__
__module____qualname__r   r!   r>   rD   rH   rL   rV   r[   ra   rj   rt   r}    r   r   r
   r
   
   s@    )
),.,(V4
-,10
d
$%r   r
   )unittestnumpyr   r{   skimage._shared.testingr   scipy.ndimager   r   skimager   r   skimage.utilr   TestCaser
   r   r   r   <module>r      s.       0 9 ! %o%!! o%r   