o
    :ήc                     @   s^   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                   @   s\   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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   G/tmp/pip-target-vg8gfxp4/lib/python/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      
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/   r0   r1   )
r   r2   r3   r4   cfr   r5   r6   r7   r8   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_shapeA   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/   r0   )r   result1result2r   r   r   test_mask_noneE   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   imagecorrect_outputr   r   r   r   test_use_quantilesK   s    
zTestCanny.test_use_quantilesc                 C   s&   t d}t t|dksJ d S )N)
   rN   r   )r   r   r0   r   r   r   rK   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@)rH   rF   rG   c   g?i   )r   r   rI   r?   r@   r   r   rO   r   r   r   test_invalid_use_quantilesa   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.r:   r;   g      ?   N)r   rI   r   r   r   r   )r   image_uint8image_floatresult_uint8result_floatlowhighr   r   r   
test_dtypeu   s   


zTestCanny.test_dtypeN)__name__
__module____qualname__r   r   r9   r>   rA   rD   rM   rP   rU   r]   r   r   r   r   r   	   s    r   )unittestnumpyr   skimage._shared.testingr   scipy.ndimager   r   skimager   r   skimage.utilr   TestCaser   r   r   r   r   <module>   s    