o
    e                     @   sf   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 de jZdS )    N)assert_equal)binary_dilationbinary_erosion)datafeature)img_as_floatc                   @   sl   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d Zdd Zdd ZdS )	TestCannyc              
   C   s4   t tddddtdt}| t| 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result r   PD:\Projects\ConvertPro\env\Lib\site-packages\skimage/feature/tests/test_canny.pytest_00_00_zeros   s   zTestCanny.test_00_00_zerosc              
   C   s8   t tjjdddddtdt}| t| 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   r   r   r   test_00_01_zeros_mask   s   
zTestCanny.test_00_01_zeros_maskc           	   
   C   s   t jddddf td \}}t t || ||  d dk }t|tdddt |j	t
}t|dd}t|dd}t |t |}| t ||  t |}| |d	k | |d
k  dS )z9Test that the Canny filter finds the outlines of a circle8         ?{Gz?r   r      Z
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_countr   r   r   test_01_01_circle   s   $$"
zTestCanny.test_01_01_circlec           
   
   C   s   t jd t jddddf td \}}t t || ||  d dk }|td t jj|j	dd  }t
|ddd	t |j	t}t|dd
}t|dd
}t |t |}| t ||  t |}	| |	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)   r*   r   r+   r   r   r   r   r   r   r,   r-   r.   r/   r0   )
r   r1   r2   r3   cfr   r4   r5   r6   r7   r   r   r   test_01_02_circle_with_noise.   s   $$"
z&TestCanny.test_01_02_circle_with_noisec                 C   s    |  ttjtdddd d S )N)r
   r
   r
   r   r   )assertRaises
ValueErrorr   r   r   r   )r   r   r   r   test_image_shapeB   s   zTestCanny.test_image_shapec              
   C   sN   t tddddtdt}t tdddd}| t||k d S )Nr	   r   r   )r   r   r   r   r   r   r.   r/   )r   Zresult1Zresult2r   r   r   test_mask_noneF   s
   zTestCanny.test_mask_nonec              	   C   sn   t t d d dd d df }tg dg dg dg dg dg dg}tj|d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   imageZcorrect_outputr   r   r   r   test_use_quantilesL   s    
zTestCanny.test_use_quantilesc                 C   s&   t d}t t|dksJ d S )N
   rK   r   )r   r   r/   r   r   r   rH   r   r   r   test_img_all_ones^   s   
zTestCanny.test_img_all_onesc                 C   s   t t d d dd d df }| jttj|dddd | jttj|dddd | jttj|dddd | jttj|ddd	d t }| jttj|ddd
d d S )N2   Tr    g@)rE   rC   rD   c   g?i   )r   r   rF   r>   r?   r   r   rL   r   r   r   test_invalid_use_quantilesb   s"    
z$TestCanny.test_invalid_use_quantilesc              	   C   sd   t  }t|}t|}t|}t|| d}d}tt|d||t|dd| d|  dS )zACheck that the same output is produced regardless of image dtype.r9   r:   g      ?   N)r   rF   r   r   r   r   )r   Zimage_uint8Zimage_floatZresult_uint8Zresult_floatlowhighr   r   r   
test_dtypev   s   


zTestCanny.test_dtypec              
   C   s@   t  }dD ]}ttj||dtj||tj|tdd qdS )zKThe masked and unmasked algorithms should return the same result.

        )ZconstantZnearestZreflect)modedtype)rW   maskN)r   rF   r   r   r   r   Z	ones_liker   )r   rH   rW   r   r   r   test_full_mask_matches_no_mask   s   z(TestCanny.test_full_mask_matches_no_maskc              	   C   sl   t jt jfD ]-}t jd|d}t |j|d< tjtdd t	
| W d    n1 s.w   Y  qd S )NrJ   rX   )r"   r"   z'64-bit integer images are not supported)match)r   Zint64Zuint64r   ZiinfomaxpytestZraisesr?   r   r   )r   rY   rH   r   r   r   test_unsupported_int64   s   z TestCanny.test_unsupported_int64N)__name__
__module____qualname__r   r   r8   r=   r@   rA   rI   rM   rR   rV   r[   r_   r   r   r   r   r   
   s    r   )Zunittestnumpyr   r^   Zskimage._shared.testingr   Zscipy.ndimager   r   Zskimager   r   Zskimage.utilr   ZTestCaser   r   r   r   r   <module>   s    