
    9i                     ^    S SK rS SKJr  SSKJr  SSKJr  SSKJ	r	          S
SS.S	 jjr
g)    N)RectBivariateSpline   )_supported_float_type)img_as_float)sobelperiodic)boundary_conditionc
                @   [        U5      nUS::  a  [        S5      eSn/ SQnX;  a   [        SSR                  U5      -   S-   5      e[        U 5      n[	        U R
                  5      nUR                  USS	9nUR                  S
:H  nUS:w  aS  U(       a?  [        USS2SS2S4   5      [        USS2SS2S4   5      [        USS2SS2S4   5      /nO[        U5      /nOS/nU(       a(  U[        R                  " USS9-  U[        U5      -  -   nOXM-  UUS   -  -   n[        [        R                  " UR                  S   5      [        R                  " UR                  S   5      UR                  SSSS9nUSS2SSS24   nUSS2S4   R                  U5      nUSS2S4   R                  U5      n[        U5      n[        R                   " UU4US9n[        R                   " UU4US9n[        R"                  " U[$        S9n[        R&                  " USSS9[        R&                  " USSS9-   SU-  -
  n[        R&                  " USSS9[        R&                  " USSS9-   S[        R&                  " USSS9-  -
  S[        R&                  " USSS9-  -
  SU-  -   nU* U-  UU-  -   nSnU
R)                  S5      (       a  SUSSS24'   SUSSS24'   / SQUSSS
24'   SnSnU
R+                  S5      (       a  SUSSS24'   SUSSS24'   / SQUSSS24'   SnSnU
R)                  S5      (       a*  SUSSS24'   / SQUSSS
24'   SUSSS24'   / SQUSSS24'   SnSnU
R+                  S5      (       a*  SUSSS24'   / SQUSSS24'   SUSSS24'   / SQUSSS24'   Sn[        R,                  R/                  UUU-  -   5      n U R                  USS	9n [1        U5       GH  n!U" UUSSS9R                  USS	9n"U" UUSSS9R                  USS	9n#U(       a
  SU"S'   SU#S'   U(       a
  SU"S'   SU#S'   U(       a  U"S==   S-  ss'   U#S==   S-  ss'   U(       a  U"S==   S-  ss'   U#S==   S-  ss'   U UU-  U"-   -  n$U UU-  U#-   -  n%U[        R2                  " U$U-
  5      -  n&U[        R2                  " U%U-
  5      -  n'U(       a
  SU&S'   SU'S'   U(       a
  SU&S'   SU'S'   UU&-  nUU'-  nU!US-   -  n(U(U:  a  UUU(SS24'   UUU(SS24'   GM3  [        R4                  " [        R6                  " [        R8                  " UUSSS24   -
  5      [        R8                  " UUSSS24   -
  5      -   S5      5      n)U)U	:  d  GM    O   [        R:                  " UU/SS9$ )a
  Active contour model.

Active contours by fitting snakes to features of images. Supports single
and multichannel 2D images. Snakes can be periodic (for segmentation) or
have fixed and/or free ends.
The output snake has the same length as the input boundary.
As the number of points is constant, make sure that the initial snake
has enough points to capture the details of the final contour.

Parameters
----------
image : (M, N) or (M, N, 3) ndarray
    Input image.
snake : (K, 2) ndarray
    Initial snake coordinates. For periodic boundary conditions, endpoints
    must not be duplicated.
alpha : float, optional
    Snake length shape parameter. Higher values makes snake contract
    faster.
beta : float, optional
    Snake smoothness shape parameter. Higher values makes snake smoother.
w_line : float, optional
    Controls attraction to brightness. Use negative values to attract
    toward dark regions.
w_edge : float, optional
    Controls attraction to edges. Use negative values to repel snake from
    edges.
gamma : float, optional
    Explicit time stepping parameter.
max_px_move : float, optional
    Maximum pixel distance to move per iteration.
max_num_iter : int, optional
    Maximum iterations to optimize snake shape.
convergence : float, optional
    Convergence criteria.
boundary_condition : string, optional
    Boundary conditions for the contour. Can be one of 'periodic',
    'free', 'fixed', 'free-fixed', or 'fixed-free'. 'periodic' attaches
    the two ends of the snake, 'fixed' holds the end-points in place,
    and 'free' allows free movement of the ends. 'fixed' and 'free' can
    be combined by parsing 'fixed-free', 'free-fixed'. Parsing
    'fixed-fixed' or 'free-free' yields same behaviour as 'fixed' and
    'free', respectively.

Returns
-------
snake : (K, 2) ndarray
    Optimised snake, same shape as input parameter.

References
----------
.. [1]  Kass, M.; Witkin, A.; Terzopoulos, D. "Snakes: Active contour
        models". International Journal of Computer Vision 1 (4): 321
        (1988). :DOI:`10.1007/BF00133570`

Examples
--------
>>> from skimage.draw import circle_perimeter
>>> from skimage.filters import gaussian

Create and smooth image:

>>> img = np.zeros((100, 100))
>>> rr, cc = circle_perimeter(35, 45, 25)
>>> img[rr, cc] = 1
>>> img = gaussian(img, sigma=2, preserve_range=False)

Initialize spline:

>>> s = np.linspace(0, 2*np.pi, 100)
>>> init = 50 * np.array([np.sin(s), np.cos(s)]).T + 50

Fit spline to image:

>>> snake = active_contour(img, init, w_edge=0, w_line=1)  # doctest: +SKIP
>>> dist = np.sqrt((45-snake[:, 0])**2 + (35-snake[:, 1])**2)  # doctest: +SKIP
>>> int(np.mean(dist))  # doctest: +SKIP
25

r   zmax_num_iter should be >0.
   )r   freefixedz
free-fixedz
fixed-freezfixed-fixedz	free-freez.Invalid boundary condition.
Should be one of: z, .F)copy   N   r   )axis)kxkys)dtype      r   )r   r   r   Tr   )r   r   r   r   )dxgrid)dyr   )int
ValueErrorjoinr   r   r   astypendimr   npsumr   arangeshapeTlenemptyeyefloatroll
startswithendswithlinalginvrangetanhminmaxabsstack)*imagesnakealphabetaw_linew_edgegammamax_px_movemax_num_iterconvergencer	   convergence_order	valid_bcsimgfloat_dtypeRGBedgeintpsnake_xyxynxsaveysaveeye_nabAsfixedefixedsfreeefreer2   ifxfyxnynr   r   jdists*                                             i/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/segmentation/active_contour_model.pyactive_contourr`   	   s   | |$Lq566I *#ii	"# 
 	
 u
C'4K
**[u*
-C
((a-C {#aAg,'s1a7|)<eC1aL>QRD#J<Ds rvvc**Vc$i-??lVd1g-- 
		#))A,399Q<!8#%%A!qD Q"W~HAk*AAk*AAAHH'+;?EHH'+;?E FF1E"E
r"RWWUBQ%??!e)K  	r"
''%!
$	%
bggeRa(
(	) bggeRa(
(	) e)		  

TAXA F$$W--!Q$!Q$!RaR%F""7++"a%"a%"bc'
E$$V,,!Q$!RaR%!Q$!!RaR%E""6**"a%"bc'
"a%#"bc'
 ))--EEM)
*C
**[u*
-C < !Q15)0050I!Q15)0050IBqEBqEBrFBrFqEQJEqEQJErFaKFrFaKFEAIN#EAIN# 27726?*27726?*BqEBqEBrFBrF	R	R "Q&'  E!Q$KE!Q$K66rvveaaj01BFF51T1W:;M4NNPQRD k!W !Z 88QF##    ){Gz?皙?g        r   rb   g      ?i	  rc   )numpyr%   scipy.interpolater   _shared.utilsr   utilr   filtersr   r`    ra   r_   <module>rj      s?     1 1   	
q$ "q$ra   