
    9iq1                         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K
r
SSKJr  SSKJr  SS	KJr  S
 r\4S jrS r\R*                  " 5       SSS.S j5       rg)    N)sparse)spsolve)laplace   )utils)label   )_build_matrix_innerc                 r    [         R                  " X-
  S5      n[         R                  " X-   S-   U5      nX44$ )Nr   r	   )npmaximumminimum)nd_idxradiusnd_shape	bounds_lo	bounds_his        [/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/restoration/inpaint.py_get_neighborhoodr      s4    

6?A.I

6?Q.9I    c                     [         R                  " XS9nSX1'   [        [        U5      5      n[         R                  " U5      nX4   n[         R                  " USS9nX4U4$ )Ndtyper	   r   axis)r   zerosr   wherestack)shapecenterr   
neigh_coefcoef_idx	coef_valss         r   _get_neigh_coefr$      sZ    %-JJ,-J xx
#H$Ixxq)H**r   c                 .	   UR                   S   nUR                   S   S-  n[        R                  " UR                   [        S9nSU[	        Xw* 5      4UR
                  -  '   X-  n	U) U-  n
[        R                  " U	5      n[        R                  " U	5      n[        R                  " U
5      n[        R                  " X45      n[        R                  " U
5      n[        [        X5       VVs/ s H  u  nn[        R                  " UU45      PM      snn5      nUS:g  n[        R                  " UU[        R                  SS9nUU   R                  5       n[        R                  " U5      n[        R                  " U5      nU[        R                  " UU:H  5      -
  n[        R                   " U[        R"                  S9n[        R$                  " UU4UR&                  S9n[        R                   " U[        R"                  S9n[        R                   " U[        R"                  S9n[        R                   " UUR&                  S9n0 nUR)                  S5      n[        R*                  " UR)                  SU45      5      n Sn!Sn"Sn#[        R,                  " USS9n[/        U5       GH  u  n#n$[1        U$XqR                   5      u  n%n&[        U&U%-
  5      n'[        U$U%-
  5      n(UR3                  U'U(4S	5      u  n)n*U)c"  [5        U'U(UR&                  S9u  n+n)n*U)U*4UU'U(4'   U)U%S
S
2[        R6                  4   -   n)[        R8                  " U)UR                   5      n,Sn-[        U*U,5       HF  u  n.n/UU/   (       a  U#UU"'   U/UU"'   U.UU"'   U"S-  n"M&  UU!S
S
24==   U.U U/S
S
24   -  -  ss'   U-S-  n-MH     U-(       d  GM  U#UU!'   U!S-  n!GM"     U#S-   n0U!n1U"n2[;        U0U1U2UUUUU UUUUU5      n3US
U3 nUS
U32S
S
24   nUUR<                  4n4[>        R@                  " UUU44U4S9n5U5S
S
2U4   n5[        R$                  " UU4UR&                  S9n6UU6US
S
24'   [C        U5U6SSS9n7U7R
                  S:X  a  U7S
S
2[        R6                  4   n7U7UU'   U$ s  snnf )a  Solve a (sparse) linear system corresponding to biharmonic inpainting.

This function creates a linear system of the form:

``A @ u = b``

where ``A`` is a sparse matrix, ``b`` is a vector enforcing smoothness and
boundary constraints and ``u`` is the vector of inpainted values to be
(uniquely) determined by solving the linear system.

``A`` is a sparse matrix of shape (n_mask, n_mask) where ``n_mask``
corresponds to the number of non-zero values in ``mask`` (i.e. the number
of pixels to be inpainted). Each row in A will have a number of non-zero
values equal to the number of non-zero values in the biharmonic kernel,
``neigh_coef_full``. In practice, biharmonic kernels with reduced extent
are used at the image borders. This matrix, ``A`` is the same for all
image channels (since the same inpainting mask is currently used for all
channels).

``u`` is a dense matrix of shape ``(n_mask, n_channels)`` and represents
the vector of unknown values for each channel.

``b`` is a dense matrix of shape ``(n_mask, n_channels)`` and represents
the desired output of convolving the solution with the biharmonic kernel.
At mask locations where there is no overlap with known values, ``b`` will
have a value of 0. This enforces the biharmonic smoothness constraint in
the interior of inpainting regions. For regions near the boundary that
overlap with known values, the entries in ``b`` enforce boundary conditions
designed to avoid discontinuity with the known values.
r   r   r   constant)outputmoder	   r   )NNN)r   FMMD_ATA)use_umfpack
permc_spec)"r   r   onesboolslicendimr   flatnonzeroconcatenatetuplezipndiconvolveuint8sumcount_nonzeroemptyintpr   r   reshapeascontiguousarrayr   	enumerater   getr$   newaxisravel_multi_indexr
   sizer   	csr_arrayr   )8imagemaskoutneigh_coef_fullr#   raveled_offsets
n_channelsr   	edge_maskboundary_maskcenter_maskboundary_pts
boundary_icenter_imask_i
center_ptsbcmask_pts	structuretmp
nnz_matrixn_maskn_structnnz_rhs_vector_maxrow_idx_known
data_knownrow_idx_unknowncol_idx_unknowndata_unknown
coef_cache	mask_flatout_flat	idx_knownidx_unknown	mask_pt_nr   b_lob_hi
coef_shapecoef_centerr"   coefs_index1dnvalscoefi	row_startknown_start_idxunknown_start_idxnnz_rhssp_shapematrix_unknownrhsresults8                                                           r   !_inpaint_biharmonic_single_regionrx   !   s   D 2J""1%*F

$/I78IuVW%'$))34$M*t#K88M*L.J~~k*H^^Z23F+&J\9VW9VAbnnaV,9VWXH  1$I
,,tYrxxj
ICTJ d#F	*H""2"23(?"CC HH/rww?M-z:#))LJhhz9Ohhz9O88Jcii8L J R I##CKKZ0@$ABHIKI88Lq1L&|4	6&vvzzB
d 4$;'
FTM*$..*k)BLQ%!0Ksyy"Ax 6>u4EJ
K01 d1bjj=11&&x< 5'*GD!|/8,/0,,0[)q 9a<(D8AqD>,AA(
 + 5'0M)$NI? 5D AIO#!!G( "(7+MHWHaK(J !H%%	9:(N
 $AvI.N ((FJ'syy
9C&Cq ^Se	RF{{a2::&CMJc Xs   .%R
F)split_into_regionschannel_axisc          	        ^ U R                   S:  a  [        S5      eUSLnU(       a  U R                  SS OU R                  nXQR                  :w  a  [        S5      e[        R                  R                  U 5      (       a  [        S5      e[        R                  " U 5      n [        R                  " U R                  5      nU R                  USS9n UR                  [        SS9nU(       d  U S	[        R                  4   n [        R                  " U S
S9nSmST-  S-   4UR                   -  nT4UR                   -  n	[!        XUR                  S9u  pnUR"                  S   nUT-
  nX)    nUR%                  SS9UR'                  SS94nU(       Ga@  [(        R*                  " UR                   S5      n[(        R,                  " UUS9n[/        U5      nUU-  n[(        R0                  " U5      n[3        US5       H  u  nn[5        U4S j[7        UUR                  5       5       5      nUU   U:H  nU[9        S5      4-  nUU   R                  5       n[        R:                  " US   R"                   Vs/ s H  nUU-  PM
     sn5      n[        R<                  " UUS	[        R                  4   -  SS9n[?        U U   UUU
UU5        UUU'   M     Op[        R:                  " US   R"                   Vs/ s H  nUU-  PM
     sn5      n[        R<                  " UUS	[        R                  4   -  SS9n[?        XXzUU5        [        R@                  " UUS   US   US9  U(       d  US   nU$ s  snf s  snf )a\  Inpaint masked points in image with biharmonic equations.

Parameters
----------
image : (M[, N[, ..., P]][, C]) ndarray
    Input image.
mask : (M[, N[, ..., P]]) ndarray
    Array of pixels to be inpainted. Have to be the same shape as one
    of the 'image' channels. Unknown pixels have to be represented with 1,
    known pixels - with 0.
split_into_regions : boolean, optional
    If True, inpainting is performed on a region-by-region basis. This is
    likely to be slower, but will have reduced memory requirements.
channel_axis : int or None, optional
    If None, the image is assumed to be a grayscale (single channel) image.
    Otherwise, this parameter indicates which axis of the array corresponds
    to channels.

    .. versionadded:: 0.19
       ``channel_axis`` was added in 0.19.

Returns
-------
out : (M[, N[, ..., P]][, C]) ndarray
    Input image with masked pixels inpainted.

References
----------
.. [1]  S.B.Damelin and N.S.Hoang. "On Surface Completion and Image
        Inpainting by Biharmonic Functions: Numerical Aspects",
        International Journal of Mathematics and Mathematical Sciences,
        Vol. 2018, Article ID 3950312
        :DOI:`10.1155/2018/3950312`
.. [2]  C. K. Chui and H. N. Mhaskar, MRA Contextual-Recovery Extension of
        Smooth Functions on Manifolds, Appl. and Comp. Harmonic Anal.,
        28 (2010), 104-113,
        :DOI:`10.1016/j.acha.2009.04.004`

Examples
--------
>>> img = np.tile(np.square(np.linspace(0, 1, 5)), (5, 1))
>>> mask = np.zeros_like(img)
>>> mask[2, 2:] = 1
>>> mask[1, 3:] = 1
>>> mask[0, 4:] = 1
>>> out = inpaint_biharmonic(img, mask)
r	   z!Input array has to be at least 1DNr&   z&Input arrays have to be the same shapezMasked arrays are not supportedF)copy.C)orderr   r   r   r   )rU   c              3      >#    U  HA  u  p[        [        UR                  T-
  S 5      [        UR                  T-   U5      5      v   MC     g7f)r   N)r/   maxstartminstop).0slrB   r   s      r   	<genexpr>%inpaint_biharmonic.<locals>.<genexpr>*  sD       AHB c"((V+Q/RWWv5Et1LMM As   A	A).r   )a_mina_maxrF   )!r0   
ValueErrorr   r   maisMaskedArray	TypeErrorskimageimg_as_floatr   _supported_float_typer   astyper.   r@   r|   r$   stridesr   r   r5   generate_binary_structurebinary_dilationr   find_objectsr>   r3   r4   r/   arrayr8   rx   clip)rD   rE   ry   rz   multichannelimg_baseshapefloat_dtyperF   rh   ri   rG   r"   r#   channel_stride_bytesoffsetsknown_pointslimitskernelmask_dilatedmask_labeledbbox_slices
idx_regionbb_sliceroi_slmask_regionotmpsostridesrH   r   s                                @r   inpaint_biharmonicr      sT   d zzA~<==t+L(4EKK$%++M

"ABB	uu5!!9::  'E --ekk:KLL5L1E;;t%;(Dc2::o&
''%s
#C Ff*q."TYY.J)dii'K+:syy,(Oy
 ;;r? G <LA&(8(8a(8(@AF..tyy!<**46B\*&&|4$-k1$= J  #Hl.@.@ A F
 'v.*<KuT{n$Fv;##%D xx48L4H4HI4Hq**4HIH !ffWxRZZ/H%HqQO-f CK9 %>> 88F@S@ST@S1Q"66@STU&&8CO+D!D1M)y/	

 GGCvayq	s;&kJ; J  Us   7M0
6M5)numpyr   scipyr   scipy.sparse.linalgr   scipy.ndimagendimager5   r   r   _sharedr   measurer   _inpaintr
   r   floatr$   rx   channel_as_last_axisr    r   r   <module>r      sZ      '  !    )  */ +aH :?d N Nr   