o
    Õjô  ã                   @   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   úa/var/www/html/Deteccion_Ine/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   é   ©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 )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)   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_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 )
Néd   )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_quantilesJ   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 )Né2   Tr    gÍÌÌÌÌÌ@)rE   rC   rD   éûÿÿÿéc   gÍÌÌÌÌÌì?iœÿÿÿé–   )r   r   rF   r>   r?   r   r   rL   r   r   r   Útest_invalid_use_quantilesd   sT    ú	ú	ú	ú

ú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_dtype–   s   


þzTestCanny.test_dtypec              
   C   s@   t  ¡ }dD ]}ttj||dtj||tj|tddƒ qdS )zAThe masked and unmasked algorithms should return the same result.)ZconstantÚnearestZreflect)Úmode©Údtype)rX   ÚmaskN)r   rF   r   r   r   r   Z	ones_liker   )r   rH   rX   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   rY   )r"   r"   z'64-bit integer images are not supported)Úmatch)r   Zint64Zuint64r   ZiinfoÚmaxÚpytestZraisesr?   r   r   )r   rZ   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    2
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    