o
    ^i                     @   s   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dl
mZ d dl
mZ d	d
 Zejdejejejejgejddddgfdddgfddg dfddg dfdddgfgdd Zejdejejejejgejdg ddd Zdd Zejddddddg dgd d! Zejd"dd#d#d$d$gd%d%ggd$d&gd%d'ggd&d&gd'd'gggfdd#d#d$d$gd&d&ggd$d%gd&d'ggd%d%gd'd'gggfdd(d(d$d$gd%d%gd)d)ggd$d&gd%d'gd)d*ggd$d+gd%d,gd)d-ggd&d&gd'd'gd*d*ggd&d+gd'd,gd*d-ggd+d+gd,d,gd-d-gggfdd(d(d$d$gd&d&gd+d+ggd$d%gd&d'gd+d,ggd$d)gd&d*gd+d-ggd%d%gd'd'gd,d,ggd%d)gd'd*gd,d-ggd)d)gd*d*gd-d-gggfdd#d#d$d$gd%d%gd'd'gd&d&gggfgd.d/ Zejd0d1d2gd3d4 ZdS )5    )shuffleN)assert_allclose)assert_array_equal)integral_image)haar_like_featurehaar_like_feature_coord)draw_haar_like_featurec               
   C   s   t jdt jd} t| }d}tt# t|dddd|d tdd|d t	| dddd|d W d    n1 s9w   Y  tddd\}}tt t|dddd|d d |d	 W d    d S 1 sfw   Y  d S )
N   r   dtypeunknown_typer   r   feature_typetype-2-x   r   feature_coord)
nponesfloat32r   pytestraises
ValueErrorr   r   r	   )imgimg_iir   
feat_coord	feat_type r   Z/var/www/html/RAG/RAG_venv/lib/python3.10/site-packages/skimage/feature/tests/test_haar.pytest_haar_like_feature_error   s   "r!   r   z1feature_type,shape_feature,expected_feature_valuer   )T   g        type-2-ytype-3-x)*   )g      g      g       g      type-3-ytype-4)$   c                 C   sD   t jd|d}t|}t|dddd| d}tt t || d S )Nr
   r   r   r   r   )r   r   r   r   r   sortunique)r   shape_featureexpected_feature_valuer   r   r   haar_featurer   r   r    test_haar_like_feature    s   r/   r   r   r#   r$   r'   r(   c                 C   s`   t jd| d}t|}|j}d|jv rt |jdd}t|dddd|d}|j|ks.J d S )	Nr
   r   uintu r   r   r   )r   r   r   r   namereplacer   )r   r   r   r   expected_dtyper.   r   r   r    !test_haar_like_feature_fused_type3   s   
r7   c                  C   sR   t jdt jd} t| }g d}t|dddd|d}t|dddd}t|| d S )Nr
   r   r0   r   r   r   )r   r   int8r   r   r   )r   r   r   	haar_listhaar_allr   r   r    test_haar_like_feature_listC   s   r;   )r#   r$   r(   c              	   C   s   t jdt jd}t|}t| tr+t|  tdd | D  \}}t |}t |}nt	dd| \}}t
|dddd||d}t
|dddd| }t|| d S )Nr
   r   c                 S   s   g | ]}t d d |qS )r   r   ).0feat_tr   r   r    
<listcomp>_   s    z6test_haar_like_feature_precomputed.<locals>.<listcomp>r   r   r   )r   r   r8   r   
isinstancelistr   zipconcatenater   r   r   )r   r   r   r   r   haar_feature_precomputedr.   r   r   r    "test_haar_like_feature_precomputedL   s   

rD   z(feature_type,height,width,expected_coord   )r   r   )r      )rF   r   )rF   rF   r   )r   rE   )rF   rE   )rE   r   )rE   rF   )rE   rE   c                 C   sD   t ||| \}}tdd |D }t|| t|| ks J d S )Nc                 S   s   g | ]}|qS r   r   )r<   hfr   r   r    r>      s    z0test_haar_like_feature_coord.<locals>.<listcomp>)r   r   arrayr   all)r   heightwidthexpected_coordr   r   r   r   r    test_haar_like_feature_coordl   s   :
rM   zmax_n_features,nnz_values)N.   )rF      c              
   C   st   t jdt jd}tddd\}}t|dddd|| dd}t|dddd|| dd |jdks/J t ||ks8J d S )Nr
   r   r   r(   r   )max_n_featuresrng)r   r   r   )r   zerosr   r   r	   shapecount_nonzero)rP   
nnz_valuesr   coord_imager   r   r    test_draw_haar_like_feature   s   rY   )randomr   r   numpyr   numpy.testingr   r   skimage.transformr   skimage.featurer   r   r	   r!   markparametrizeuint8r8   r   float64r/   r7   r;   rD   rM   rY   r   r   r   r    <module>   s    



	

9