
    k hP                     z    d dl Zd dlmZmZmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZ dZddZ G d	 d
e      Zy)    N)max_treearea_closingarea_opening)max_tree_local_maximadiameter_opening)diameter_closing)invert)assert_array_equalTestCaseg-q=c                     || |fi |}t        ||       t        j                  t        j                  fD ]:  }| j	                  |      } |||fi |}|j	                  |      }	t        ||	       < | j	                  t        j
                        }
|
dz  }
|j	                  t        j
                        }|dz  }|r|dz  }n|}t        j                  t        j
                  fD ]W  }|
j	                  |      } |||fi |}|j	                  |      }	d|	z  d|z  z
  }|dk\  j                         }|t        k  rWJ  | j	                  t        j                        }|dz
  }|j	                  t        j                        }|dz
  }t        j                  t        j                  t        j                  t        j                  fD ]:  }|j	                  |      } |||fi |}|j	                  |      }t        ||       < y )Ng     o@      ?   )r
   npuint32uint64astypefloat64float32sumepsint16int8int32int64)imgparamexpectedfuncparam_scalekeywordsoutdtimg_castexp_cast
data_floatexpected_float
param_cast	data_cast	error_imgerror
img_signed
exp_signedimg_sexp_ss                       /home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/skimage/morphology/tests/test_max_tree.py_full_type_testr0      s   
sE
&X
&CsH% yy"))$ *::b>8U/h/??2&3)	* BJJ'Je#J__RZZ0N#e+NU]

zz2::& %%b)	9j5H5!((,H$us{2	c!&&(s{{ BHH%Jc!J*Jc!Jww"((BHH5 '!!"%5%,8,!!"%3&	'    c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestMaxtreec                 
   t         j                  }t        j                  g dg dg dg dg|      }t        j                  g dg dg dg d	gt         j                        }t        j                  g d
t         j                        }t         j                  t         j                  t         j
                  t         j                  fD ];  }|j                  |      }t        |d      \  }}t        ||       t        ||       = t         j                  t         j                  t         j                  t         j                  fD ]@  }|j                  |      }|dz
  }t        |d      \  }}t        ||       t        ||       B |j                  t              }|dz
  dz  }t         j                  t         j                  fD ];  }|j                  |      }t        |d      \  }}t        ||       t        ||       = y)zTest for max tree)
      r6   	   )   r8   r7   r7   )r6   r8   r5   r5   )r7   r7   r5   r5   dtype)      r;   r;   )r<   r<      r=   )r;   r<   r=   r5   )r=   r=   r5   r5   )r<      r7   r;      r6   r=      r8         r   r5            r?   connectivityr7   r6   g       @N)r   uint8arrayr   uint16r   r   r   r   r
   r   r   r   floatr   r   )	selfimg_typer   P_expS_expPSimg_shifted	img_floats	            r/   test_max_treezTestMaxtree.test_max_tree6   s   88hhL..I

 <Grxx
 B"((
 299biiC 	)H**X&CCa0DAqq%(q%(		) "((BHHbhh? 	)H**X&C'KKa8DAqq%(q%(	) JJu%	]c)	RZZ0 	)H!((2IIA6DAqq%(q%(		) 	r1   c                 f   t        j                  g dg dg dg dg dg dg dg dg dg d	g d
g dgt         j                        }t        j                  g dg dg dg dg dg dg dg dg dg dg dg dgt         j                        }t        j                  g dg dg dg dg dg dg dg dg dg dg dg dgt         j                        }t        |d|t        d       t        |d|t        d       t        t        |      d      \  }}t        |d|t        ||       y)z/Test for Area Closing (2 thresholds, all types))   rV   rV   rV   rV   rV   rV   rV   rV   rV   rV   rV   )rV      rW   rV   rW   rV   rW   rW   rV   rV   rW   rV   )rV   rW   (   rV   rV   rV   rV   rV   rV   rV   rX   rV   )rV   rV   rV   rV   d   rV   rY   rY   rV   rV   rW   rV   )rW   rW   rW   rW   rW   rW   rW   rV   rW   rW      rZ   )rW   rZ   rW   rW   rW   rZ   rW   rV   rZ   rZ   rZ   rX   )rW   rW   rW   rY   rW   rW   rW   rV   rZ   rZ   rZ   rZ   )rW   rW   rW   rY   rW   rW   rW   rV   rW   rW   rZ   rZ   )rW   rW   rW   rW   rW   rX   rW   rV   rV   rY   rZ   rZ   )rW   rX   rZ   rZ   rZ   rX   rW   rZ   rW   rW   rZ   rZ   )rW   rW   rW   rW   rW   rW   rW   rZ   rZ   rZ   rZ   rZ   r9   )rV   rW   rW   rV   rV   rV   rW   rW   rV   rV   rW   rV   )rV   rW   rW   rV   rV   rV   rV   rV   rV   rV   rW   rV   )rV   rV   rV   rV   rV   rV   rY   rY   rV   rV   rW   rV   )rW   rZ   rW   rW   rW   rZ   rW   rV   rZ   rZ   rZ   rZ   )rW   rW   rW   rW   rW   rX   rW   rV   rV   rW   rZ   rZ   )rW   rW   rZ   rZ   rZ   rX   rW   rZ   rW   rW   rZ   rZ   )rV   rW   rW   rV   rV   rV   rV   rV   rV   rV   rV   rV   )rW   rW   rW   rW   rW   rW   rW   rV   rV   rV   rZ   rZ   )rW   rW   rW   rW   rW   rW   rW   rV   rZ   rZ   rZ   rZ   )rW   rW   rW   rW   rW   rW   rW   rV   rV   rW   rZ   rZ   )rW   rW   rZ   rZ   rZ   rW   rW   rZ   rW   rW   rZ   rZ   r?   rF   r<   parenttree_traverserN)r   rI   rH   r0   r   r   r	   rL   r   
expected_2
expected_4rP   rQ   s         r/   test_area_closingzTestMaxtree.test_area_closing]   s    hhLLJLLLKLLKJL ((
& XXLLLLLLLLLKKL ((

& XXLLLLLLLLLLLL ((

& 	Q
LqIQ
LqIs!41Q
LSTUr1   c                 T   t        j                  g dg dg dg dg dg dg dg dg dg d	g d
g dgt         j                        }t        j                  g dg dg dg dg dg dg dg dg dg dg dg dgt         j                        }t        j                  g dg dg dg dg dg dg dg dg dg dg dg dgt         j                        }t        |d|t        d       t        |d|t        d       t        |d      \  }}t        |d|t        ||       y)z/Test for Area Opening (2 thresholds, all types))rE   rE   rE   rE   rE   rE   rE   rE   rE   rE   rE   rE   )rE   7   rc   rE   rc   rE   rc   rc   rE   rE   rc   rE   )rE   rc      rE   rE   rE   rE   rE   rE   rE   rd   rE   )rE   rE   rE   rE      rE   re   re   rE   rE   rc   rE   )rc   rc   rc   rc   rc   rc   rc   rE   rc   rc   r   r   )rc   r   rc   rc   rc   r   rc   rE   r   r   r   rd   )rc   rc   rc   re   rc   rc   rc   rE   r   r   r   r   )rc   rc   rc   re   rc   rc   rc   rE   rc   rc   r   r   )rc   rc   rc   rc   rc   rd   rc   rE   rE   re   r   r   )rc   rd   r   r   r   rd   rc   r   rc   rc   r   r   )rc   rc   rc   rc   rc   rc   rc   r   r   r   r   r   r9   )rE   rc   rc   rE   rE   rE   rc   rc   rE   rE   rc   rE   )rE   rc   rc   rE   rE   rE   rE   rE   rE   rE   rc   rE   )rE   rE   rE   rE   rE   rE   re   re   rE   rE   rc   rE   )rc   r   rc   rc   rc   r   rc   rE   r   r   r   r   )rc   rc   rc   rc   rc   rd   rc   rE   rE   rc   r   r   )rc   rc   r   r   r   rd   rc   r   rc   rc   r   r   )rE   rc   rc   rE   rE   rE   rE   rE   rE   rE   rE   rE   )rc   rc   rc   rc   rc   rc   rc   rE   rE   rE   r   r   )rc   rc   rc   rc   rc   rc   rc   rE   r   r   r   r   )rc   rc   rc   rc   rc   rc   rc   rE   rE   rc   r   r   )rc   rc   r   r   r   rc   rc   r   rc   rc   r   r   r?   rF   r<   r[   N)r   rI   rH   r0   r   r   r^   s         r/   test_area_openingzTestMaxtree.test_area_opening   s    hh@@BC@><=?@<; ((
& XX@@@B@>:=??;; ((

& XX@@@@@>:<>>:; ((

& 	Q
LqIQ
LqI!,1Q
LSTUr1   c                 f   t        j                  g dg dg dg dg dg dg dg dg dg dg d	g dgt         j                  
      }t        j                  g dg dg dg dg dg dg dg dg dg dg d	g dgt         j                  
      }t        j                  g dg dg dg dg dg dg dg dg dg dg dg dgt         j                  
      }t        |d|t        d       t        |d|t        d       t        t        |      d      \  }}t        |d|t        ||       y)3Test for Diameter Opening (2 thresholds, all types))a   _   ]   \   [   Z   rn   rn   rm   rl   rk   rj   )rj   rk   rm   Y   X   rp   rp   rp   rp   ro   rm   rk   )rk   ?   rq   rq   rq   V   rr   rr   W   +   rt   rm   )rl   ro   rp   rr   U   ru   T   ru   ru   rt   rt   ro   )rm   rp   rs   ru   rv   rv   S   rv   rv   ru   rs   rp   )rn   rp   rr   ru   rv   rw   rw   rw   rv   ru   rr   rp   )rn   rp   rr   rv   rw   rw   R   rw   rw   rv   rr   rp   )rl   ro      ry   ru   ru   rv   ru   ru   r=   r=   ro   )rk   rm   ry   ry   rs   rr   rr   rr   rs   rp   r=   rm   r9   )rn   rp   rr   rv   rw   rw   rw   rw   rw   rv   rr   rp   )rk   rq   rq   rq   rq   rr   rr   rr   rs   rv   rv   rm   )rl   ro   rp   rr   ru   ru   rv   ru   ru   rv   rv   ro   )rl   ro   rv   rv   ru   ru   rv   ru   ru   rv   rv   ro   )rk   rm   rv   rv   rs   rr   rr   rr   rs   rp   rv   rm   r?   rF   r<   r[   N)r   rI   rH   r0   r   r   r	   r   rL   r   ex2ex4rP   rQ   s         r/   test_diameter_closingz!TestMaxtree.test_diameter_closing   s   hh@@@@@@@@@>?@ ((
$ hh@@@@@@@@@>?@ ((
$ hh@@@@@@@@@@@@ ((
& 	Q%5AFQ%5AFs!41Q%5aPQRr1   c                    t        j                  g dg dg dg dg dg dg dg dg dg dg d	g dg      }t        j                  g dg dg dg dg dg dg d
g dg dg dg d	g dg      }t        j                  g dg dg dg dg dg dg d
g dg dg dg dg dg      }t        |d|t        d       t        |d|t        d       t	        |d      \  }}t        |d|t        ||       y)rh   )r>   r8   r7   rC   rA   rA   rA   rA   rA   rC   r7   r8   )r8   r5   rC   rB   rD   rD   rE   rD   rD   rB   rC   r5   )r7   rX   rX   rX   rX      r   r   r   <   r   rC   )rC   rB   rE   r         r   r   r   r   r   rB   )rA   rD   r   r   r      r   r   r   r   r   rD   )rA   rD   r   r   r   r   r   r   r   r   r   rD   )rA   rE   r   r   r   r      r   r   r   r   rE   )rC   rB   P   r   r   r   r   r   r   rY   rY   rB   )r7   rC   r   r   r   r   r   r   r   rE   rY   rC   )rA   rE   r   r   r   r   r   r   r   r   r   rE   )r7   rX   rX   rX   rX   r   r   r   r   r   r   rC   )rC   rB   rE   r   r   r   r   r   r   r   r   rB   )rC   rB   r   r   r   r   r   r   r   r   r   rB   )r7   rC   r   r   r   r   r   r   r   rE   r   rC   r?   rF   r<   r[   N)r   rI   r0   r   r   rz   s         r/   test_diameter_openingz!TestMaxtree.test_diameter_opening"  s    hh;??@@@@@@B@?
" hh;??@@@@@@B@?
" hh;??@@@@@@@??
$ 	Q%5AFQ%5AF!,1Q%5aPQRr1   c                    t        j                  g dg dg dg dg dg dg dg dg dg dg
t         j                  	      }t        j                  g d
g d
g dg dg d
g dg d
g dg dg d
g
t         j                  	      }t         j                  t         j                  t         j                  t         j
                  fD ]  }|j                  |      }t        |d      }|dkD  }t        ||       |j                  |j                  k(  sJ t        j                  |      dk(  sJ t        |      \  }}t        |||      }t        ||       |j                  |j                  k(  sJ t        j                  |      dk(  rJ  y)z#local maxima for various data types)
r5   rC   rB   rD   rD   rE   rD   rD   rB   rC   )
rC   rB   rE   r   r   r   r   r   rE   rB   )
rB   rE   rX   rX   r   r   r   r   r   rE   )
rD   r   rX   rX   r   r   r   r   r   r   )
rD   r   r   r   r   r   r   r   r   r   )
rE   r   r   r   r   r   r   r   r   r   )
rD   r   r   r   r   r   r   rY   rY   r   )
rB   rE   r   r   r   r   r   rY   rY   rE   r9   
r   r   r   r   r   r   r   r   r   r   
r   r   r;   r;   r   r   r   r;   r;   r   )
r   r   r   r   r   r;   r   r   r   r   r;   rF   r   r>   r[   N)r   rI   rH   r   r   r   r   r   r
   r:   maxr   )	rL   dataexpected_resultr:   	test_datar!   out_binrP   rQ   s	            r/   test_local_maximazTestMaxtree.test_local_maxima^  sQ   xx8888888::8 ((
 ((.......... ))
 hh		277BHH= 	$EE*I'	BCAgG899 5 555566#;!###I&DAq'	!ANC899 5 555566#;!###	$r1   c                    t        j                  g dg dg dg dg dg dg dg dg dg dg
t         j                  	      }t        j                  g d
g d
g dg dg d
g dg d
g dg dg d
g
t         j                  	      }t	        |d      }|dkD  }t        ||       t        j                  |      dk(  sJ y)zspecific tests for float type)
g?)\(?p=
ף?Q?r   333333?r   r   r   r   )
r   r   r   {Gz?r   r   r   r   r   r   )
r   r   皙?r   
ףp=
?r   r   333333?r   r   )
r   r   r   r   RQ?r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   )
r   gK?r   r   g&1?g?r   r   r   r   )
r   r   皙?r   r   r   r   g      @r   r   )
r   r   r   r   r   r   r   r   r   r   r9   r   r   )
r   r;   r   r   r;   r   r   r   r   r   )
r   r   r;   r;   r   r   r   r;   r   r   )
r   r   r;   r;   r   r   r   r   r   r   r;   rF   r   r@   N)r   rI   r   rH   r   r
   r   )rL   r   r   r!   r   s        r/   test_extrema_floatzTestMaxtree.test_extrema_float  s    xxLLLLLNLJJL **
  ((.......... ((
" $Dq9'?G4vvc{ar1   c                 6   t        j                  dt         j                        }t        j                  dt         j                        }d|dddddf<   d|d<   d|dddddf<   d|d<   d|dd	ddf<   d|dd	ddf<   d|d
dd	dd	f<   d|d<   d|dddddf<   |d
ddd	dd	fxx   dz  cc<   d|d
dd	dd	f<   d|dddddf<   d|dd	dd	dd	f<   d|d<   d|d<   t	        |      }|d
kD  }t        ||       t        j                  |      dk(  sJ y)z$tests the detection of maxima in 3D.)r6   r6   r6   r9   rY   r;   r=   rW   )r?   r?   r?   r>   r6   r   )r;   r@   r@   r?   r8   2   r@   rZ   )r8   r8   r8   N)r   zerosrH   r   r   r
   r   )rL   r   local_maximar!   r   s        r/   test_3dzTestMaxtree.test_3d  s   hhy1xx	; AqsAaCKGAqsAaCK !W AaCAI"#QqS!QY AqsAaCKGAqsAaCKAaC1acMb $%Q!QqS[!$%Q!QqS[! !AaC1acMG !W#C('<1vvc{ar1   N)__name__
__module____qualname__rT   ra   rf   r}   r   r   r   r    r1   r/   r3   r3   5   s7    %NAVFAVF=S~:Sx.$`& P r1   r3   )F)numpyr   skimage.morphologyr   r   r   r   r   r   skimage.utilr	   skimage._shared.testingr
   r   r   r0   r3   r   r1   r/   <module>r      s3     C C F /  @&'R` ( ` r1   