o
    ðËh	  ã                   @   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   ú[/var/www/html/scripts/venv/lib/python3.10/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 circleé8ÿÿÿéÈ   ç      à?ç{®Gáz”?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_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/   r0   )r   Úresult1Ú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 )
Néd   )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_quantilesL   s    ûÿ
ÿzTestCanny.test_use_quantilesc                 C   s&   t  d¡}t  t |¡dk¡sJ ‚d S )N©é
   rO   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 )Né2   Tr    gÍÌÌÌÌÌ@)rH   rF   rG   éûÿÿÿéc   gÍÌÌÌÌÌì?iœÿÿÿé–   )r   r   rI   r?   r@   r   r   rP   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.r:   r;   g      ð?éÿ   N)r   rI   r   r   r   r   )r   Úimage_uint8Úimage_floatÚresult_uint8Ú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.

        )ÚconstantÚnearestÚreflect)Úmode©Údtype)rb   ÚmaskN)r   rI   r   r   r   r   Ú	ones_liker   )r   rK   rb   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 )NrN   rc   )r"   r"   z'64-bit integer images are not supported)Úmatch)r   Úint64Úuint64r   ÚiinfoÚmaxÚpytestÚraisesr@   r   r   )r   rd   rK   r   r   r   Útest_unsupported_int64’   s   ÿý€ýz TestCanny.test_unsupported_int64N)Ú__name__Ú
__module__Ú__qualname__r   r   r9   r>   rA   rD   rM   rQ   rV   r^   rg   ro   r   r   r   r   r   
   s    r   )ÚunittestÚnumpyr   rm   Úskimage._shared.testingr   Úscipy.ndimager   r   Úskimager   r   Úskimage.utilr   ÚTestCaser   r   r   r   r   Ú<module>   s    