+
    åûj¿  ã                   óz  € R t ^ RIHtHtHt ^ RIt^ RIHu Ht	 ^ RIHt ^ RI
Ht ^ RIHt ^ RIHtHt ^ RIHtHtHt ^ RIHt ^ R	IHt ^R
IHt ^RIHtHtHt . R"OtR#R R llt R R lt!R R lt"R#R R llt#R$R R llt$R%R R llt%R#R R llt&R&R R llt'R R lt(R R  lt) ! R! R]PT                  4      t+R# )'uÒ  Crop image regions by integer slicing, by boxes or by a matrix, at a given output size.

The crop functions take channels-first images ``(B, C, H, W)`` and raise for an unbatched one. A box is
``(B, 4, 2)``: four ``(x, y)`` pixel corners, top-left, top-right, bottom-right, bottom-left, with **inclusive**
coordinates, so box ``(1, 1)``..``(2, 2)`` is a 2x2 pixel block, and the corners of an exclusive ``xyxy`` box
(torchvision) select one more row and column (`#3934 <https://github.com/kornia/kornia/issues/3934>`_). Sizes are
``(h, w)``. Except for the integer slicing of :func:`crop_by_indices` and of the default mode of
:class:`CenterCrop2D`, the crops resample by a sourceâ†’destination pixel matrix through
:func:`~kornia.geometry.transform.warp_affine` or :func:`~kornia.geometry.transform.warp_perspective`, into an output
window that starts at destination pixel ``(0, 0)``. For these the matrix is in pixels, so ``align_corners`` changes
only how ``'reflection'`` padding mirrors (about the outer pixel centres with ``True``, about the outer pixel edges
with ``False``) and, in ``'nearest'`` mode, which pixel a sample exactly halfway between two pixels takes.

Which function to use:

- An axis-aligned box by integer slicing, without interpolation, resized or padded where the slices differ in size:
  :func:`crop_by_indices`.
- Any four-corner box resampled to a fixed ``(h, w)``: :func:`crop_and_resize`; mapped onto a second box whose size
  sets the output: :func:`crop_by_boxes`.
- A crop given as a sourceâ†’destination pixel matrix, ``(B, 2, 3)`` or ``(B, 3, 3)``: :func:`crop_by_transform_mat`.
- The central window of each image: :func:`center_crop`, or :class:`CenterCrop2D` (module form, slicing by default).
- For volumes, use :func:`~kornia.geometry.transform.crop_and_resize3d` and the other ``3d`` crops; in an
  augmentation pipeline, :class:`~kornia.augmentation.RandomCrop`, :class:`~kornia.augmentation.RandomResizedCrop` or
  :class:`~kornia.augmentation.CenterCrop`.
)ÚOptionalÚTupleÚUnionN)Únn)ÚResample)Ú_emit_deprecation_warning)ÚKORNIA_CHECKÚKORNIA_CHECK_SHAPE)Ú_samples_half_in_float32Úis_compilingÚis_exporting)Úinfer_bbox_shape)Ú_compiled_slice_resize)Úresize)Úget_perspective_transformÚwarp_affineÚwarp_perspectiveÚCenterCrop2Dc                óÊ   € V ^8„  d   QhR\         P                  R\         P                  R\        \        \        3,          R\        R\        R\
        R\         P                  /# )é   Úinput_tensorÚboxesÚsizeÚmodeÚpadding_modeÚalign_cornersÚreturn©ÚtorchÚTensorr   ÚintÚstrÚbool)Úformats   "Ú\C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\transform\crop2d.pyÚ__annotate__r%   F   sk   € ÷ lñ lÜ—,‘,ðlä�<‰<ðlô ””S��/ðlô ð	lô
 ðlô ðlô ‡\�\ñló    c           	     ód  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\        P                  4      '       g   \        R\	        V4       24      h\        V\
        \        34      '       d   \        V4      ^8w  d   \        RV 24      h\        V P                  4      ^8w  d   \        RV P                   R24      hVw  rgVP                  V P                  \        P                  ! V P                  \        P                  4      R7      p\        P                   ! ^ ^ .V^,
          ^ .V^,
          V^,
          .^ V^,
          ...V P                  VP                  R7      P#                  VP                  ^ ,          RR4      p	\%        WW–V3W4V4      # )aÉ  Crop a four-corner box from each image and resample it to a fixed output size.

``patches = crop_and_resize(input_tensor, boxes, size)`` takes images ``(B, C, H, W)`` and boxes ``(B, 4, 2)``, one
per image or ``(1, 4, 2)`` for all of them, and returns the ``(B, C, h, w)`` patches for ``size = (h, w)``. The box
corners land on the corner pixels of the patch: a rectangle is resized corner to corner, any other quadrilateral is
rectified by the homography between the two, and the patch is differentiable with respect to the corners. A single
image does not broadcast over a batch of boxes. For an exact integer slice without interpolation, use
:func:`crop_by_indices`; to place the crop by a second box, :func:`crop_by_boxes`; for volumes,
:func:`crop_and_resize3d`.

Convention:
    - see :doc:`Conventions & Pitfalls </get-started/conventions>` for the ``align_corners``
      defaults and sampling rules
    - a ``float16`` or ``bfloat16`` image is cropped in ``float32``, its homography solved and kept in
      ``float32``, and the patches rounded once to the image dtype; ``float32`` boxes keep their precision
    - input: ``(B, C, H, W)``; ``size`` is ``(h, w)``
    - ``boxes``: ``(B, 4, 2)`` corner points in ``(x, y)`` order
      top-left, top-right, bottom-right, bottom-left; coordinates are
      **inclusive** pixel positions (box ``(1, 1)``..``(2, 2)`` selects a
      :math:`2 \times 2` pixel block), origin at top-left
    - a box axis of one pixel is cropped exactly when ``size`` is one pixel on that axis too; one pixel in the box
      but not in ``size``, or the reverse, has no invertible matrix and returns NaN (a meaningless finite value
      with ``mode='nearest'``), and so does a box with no homography to the patch, such as a triangle
      (`#4747 <https://github.com/kornia/kornia/issues/4747>`_)

Args:
    input_tensor: the 2D image torch.Tensor with shape ``(B, C, H, W)``.
    boxes : a torch.Tensor containing the coordinates of the bounding boxes to be extracted.
        The torch.Tensor must have the shape of ``(B, 4, 2)``, where each box is defined in the following
        (clockwise) order: top-left, top-right, bottom-right and bottom-left. The coordinates must be in the x, y
        order.
    size: a tuple with the height and width that will be
        used to resize the extracted patches.
    mode: interpolation mode to calculate output values
      ``'bilinear'`` | ``'nearest'``.
    padding_mode: padding mode for outside grid values
      ``'zeros'`` | ``'border'`` | ``'reflection'``.
    align_corners: mode for grid_generation.

Returns:
    the patches, with shape ``(B, C, h, w)`` for ``size = (h, w)``.

See Also:
    - :func:`crop_by_indices`: integer slicing of axis-aligned boxes, without interpolation.
    - :func:`crop_by_boxes`: maps the box onto a second box, whose size sets the output size.
    - :func:`crop_and_resize3d`: the same for volumes and ``(B, 8, 3)`` boxes; pass ``align_corners=True`` there.
    - :func:`resize`: the whole image; for an image and a ``size`` of at least 2 pixels on each axis, bilinear
      ``crop_and_resize`` of the image's corner box equals ``resize(input, size, align_corners=True)``.
    - :class:`~kornia.augmentation.RandomResizedCrop`: random boxes resized to a fixed size, in an augmentation
      pipeline.

Example:
    >>> input = torch.tensor([[[
    ...     [1., 2., 3., 4.],
    ...     [5., 6., 7., 8.],
    ...     [9., 10., 11., 12.],
    ...     [13., 14., 15., 16.],
    ... ]]])
    >>> boxes = torch.tensor([[
    ...     [1., 1.],
    ...     [2., 1.],
    ...     [2., 2.],
    ...     [1., 2.],
    ... ]])  # 1x4x2
    >>> crop_and_resize(input, boxes, (2, 2), mode='nearest', align_corners=True)
    tensor([[[[ 6.,  7.],
              [10., 11.]]]])

ú3Input torch.tensor type is not a torch.Tensor. Got z,Input boxes type is not a torch.Tensor. Got ú1Input size must be a tuple/list of length 2. Got ú9Only torch.Tensor with shape (B, C, H, W) supported. Got Ú.©ÚdeviceÚdtypeéÿÿÿÿ)Ú
isinstancer   r   Ú	TypeErrorÚtypeÚtupleÚlistÚlenÚ
ValueErrorÚshapeÚAssertionErrorÚtor-   Úpromote_typesr.   Úfloat32ÚtensorÚexpandÚ_crop_by_boxes_to_size)
r   r   r   r   r   r   Údst_hÚdst_wÚ
points_srcÚ
points_dsts
   &&&&&&    r$   Úcrop_and_resizerC   F   s‚  € ôZ �l¤E§L¡L×1Ò1ÜÐMÌdÐS_ÓN`ÐMaÐbÓcÐcä�eœUŸ\™\×*Ò*ÜÐFÄtÈEÃ{ÀmÐTÓUÐUä�dœU¤D˜M×*Ò*¬c°$«i¸1¬nÜÐLÈTÈFÐSÓTÐTä
ˆ<×ÑÓ !Ô#ÜÐXÐYe×YkÑYkÐXlÐlmÐnÓoÐoð �L€Eð
 —‘ ×!4Ñ!4¼E×<OÒ<OÐP\×PbÑPbÔdi×dqÑdqÓ<r�Ós€Jô —’Øˆaˆ&�5˜1•9˜a�. 5¨1¥9¨e°a­iÐ"8¸1¸eÀa½i¸.Ð	IÐJØ×"Ñ"à×Ñô	÷
 �fˆZ×Ñ˜aÕ  " bÓ)ð ô "Ø *°e¨n¸dÐR_óð r&   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# ©r   ÚsrcÚdstr   ©r   r   )r#   s   "r$   r%   r%   µ   s-   € ÷ ñ œ5Ÿ<™<ð ¬e¯l©lð ¼u¿|¹|ñ r&   c                óØ   € \         P                  ! ^V P                  V P                  R7      P	                  V P
                  ^ ,          ^^4      pVR,          V R,          ,
          VR&   V# )zðReturn the matrix of a crop, which only moves the first ``src`` vertex onto the first ``dst`` vertex.

Solving the perspective system from the four vertices instead fails for a crop with a size-1 axis, whose
vertices are collinear (#4751).
r,   ©ºNNNé    ©rK   ºNr   Nr   )r   Úeyer-   r.   Úrepeatr7   )rF   rG   Ú	transforms   && r$   Ú_crop_translationrR   µ   sU   € ô —	’	˜! C§J¡J°c·i±iÔ@×GÑGÈÏ	É	ÐRSÍÐVWÐYZÓ[€IØ˜d�) c¨$¥iÕ/€IˆhÑØÐr&   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# rE   rH   )r#   s   "r$   r%   r%   À   s-   € ÷ ñ ¤§¡ð ´E·L±Lð ÄUÇ\Á\ñ r&   c                óJ  € V R,          V R,          ,
          pVR,          VR,          ,
          pV^ 8H  V^ 8H  ,          p\         P                  ! V\         P                  ! V4      V4      p\         P                  ! V\         P                  ! V4      W5,          4      p\         P                  ! ^V P                  V P
                  R7      P                  V P                  ^ ,          ^^4      pVR,          VR&   VR,          VR&   VR,          W`R,          ,          ,
          VR&   V# )a  Return the matrix of an axis-aligned crop, which maps ``src`` vertices 0 and 2 onto ``dst`` vertices 0 and 2.

An axis where both boxes have zero extent (a size-1 crop) is a plain translation. An axis where only one
of them does has no invertible matrix and gives a non-finite one.
r,   ©rK   r   rJ   ©rK   rL   rL   )rK   é   )rK   rW   rW   rM   )r   ÚwhereÚ	ones_likerO   r-   r.   rP   r7   )rF   rG   Ú
src_extentÚ
dst_extentÚ	both_zeroÚsafe_src_extentÚscalerQ   s   &&      r$   Ú_crop_scale_translationr_   À   så   € ð �T•˜S �YÕ&€JØ�T•˜S �YÕ&€JØ˜q‘ Z°1¡_Õ5€Iô —k’k )¬U¯_ª_¸ZÓ-HÈ*ÓU€OÜ�KŠK˜	¤5§?¢?°:Ó#>À
Õ@\Ó]€EÜ—	’	˜! C§J¡J°c·i±iÔ@×GÑGÈÏ	É	ÐRSÍÐVWÐYZÓ[€IØ˜t�€IˆgÑØ˜t�€IˆgÑØ˜d�) e°$­iÕ&7Õ7€IˆhÑØÐr&   c                óª   € V ^8„  d   QhR\         P                  R\        \        \        3,          R\        R\        R\
        R\         P                  /# )r   r   r   r   r   r   r   r   )r#   s   "r$   r%   r%   Ø   s\   € ÷ eñ eÜ—,‘,ðeä
””S��/ðeô ðeô ð	eô
 ðeô ‡\�\ñer&   c           	     óÖ  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\
        \        34      '       d   \        V4      ^8w  d   \        RV 24      h\        V P                  4      ^8w  d   \        RV P                   R24      hVw  rVV P                  RR w  rxV^,          p	V^,          p
V^,          pV^,          p\        WÊ,
          4      p\        W¹,
          4      pWÖ,           ^,
          pWå,           ^,
          p\        P                  ! WÞ.Wþ.VV.VV...V P                  V P                  R7      p\        P                  ! ^ ^ .V^,
          ^ .V^,
          V^,
          .^ V^,
          ...V P                  V P                  R7      P                  VP                  ^ ,          R	R	4      p\!        VV4      p\#        V VWV3W#VR7      # )
u‰	  Crop the central window of each image to a given size, in one call.

``patches = center_crop(input_tensor, size)`` takes images ``(B, C, H, W)`` and returns their central
``(B, C, h, w)`` windows for ``size = (h, w)``: a sub-image of the input, with the extra pixel of an odd margin at
the bottom/right. A ``size`` larger than the input pads by ``padding_mode`` (zeros by default), again with the extra
pixel at the bottom/right. The crop is an integer translation sampled by
:func:`~kornia.geometry.transform.warp_perspective`, so it is exact up to float rounding. For the module form, which
slices by default, use :class:`CenterCrop2D`; for volumes, :func:`center_crop3d`.

Convention:
    - input: ``(B, C, H, W)`` (strictly 4D â€” no unbatched ``(C, H, W)``/
      ``(H, W)`` input is accepted); ``size`` is ``(h, w)``
    - offset: the crop starts at the integer pixel ``int(H / 2 - h / 2)`` (likewise for the width), as in
      :class:`CenterCrop2D`, so the output is a sub-image of the input. With an odd margin the extra pixel is
      left at the bottom/right; for a ``size`` larger than the input, the extra padding pixel goes there too.

Args:
    input_tensor: the 2D image torch.Tensor with shape ``(B, C, H, W)``.
    size: a tuple with the expected height and width
      of the output patch.
    mode: interpolation mode to calculate output values
      ``'bilinear'`` | ``'nearest'``.
    padding_mode: padding mode for outside grid values
      ``'zeros'`` | ``'border'`` | ``'reflection'``.
    align_corners: mode for grid_generation.

Returns:
    the central windows, with shape ``(B, C, h, w)``.

See Also:
    - :class:`CenterCrop2D`: the module form; slices with integer indices by default instead of resampling.
    - :func:`center_crop3d`: the central window of each volume; keep its default ``align_corners=True``.
    - :func:`crop_and_resize`: a window at any box, resampled to a fixed size.
    - :class:`~kornia.augmentation.CenterCrop`: the same windows as an augmentation, for augmentation pipelines;
      it raises for a ``size`` larger than the input instead of padding.

Examples:
    >>> input = torch.tensor([[[
    ...     [1., 2., 3., 4.],
    ...     [5., 6., 7., 8.],
    ...     [9., 10., 11., 12.],
    ...     [13., 14., 15., 16.],
    ...  ]]])
    >>> center_crop(input, (2, 4), mode='nearest', align_corners=True)
    tensor([[[[ 5.,  6.,  7.,  8.],
              [ 9., 10., 11., 12.]]]])

r(   r)   r*   r+   Nr,   ©r   r   r   éþÿÿÿr/   )r0   r   r   r1   r2   r3   r4   r5   r6   r7   r8   r    r<   r-   r.   r=   rR   Úcrop_by_transform_mat)r   r   r   r   r   r?   r@   Úsrc_hÚsrc_wÚ
dst_h_halfÚ
dst_w_halfÚ
src_h_halfÚ
src_w_halfÚstart_xÚstart_yÚend_xÚend_yrA   rB   rQ   s   &&&&&               r$   Úcenter_cropro   Ø   sß  € ôn �l¤E§L¡L×1Ò1ÜÐMÌdÐS_ÓN`ÐMaÐbÓcÐcä�dœU¤D˜M×*Ò*¬c°$«i¸1¬nÜÐLÈTÈFÐSÓTÐTä
ˆ<×ÑÓ !Ô#ÜÐXÐYe×YkÑYkÐXlÐlmÐnÓoÐoð �L€EØ×%Ñ% b cÐ*�L€Eð  �	€JØ �	€JØ �	€JØ �	€Jô �zÕ.Ó/€GÜ�zÕ.Ó/€Gà• 1Õ$€EØ• 1Õ$€Eô  %Ÿ|š|ØÐ
˜uÐ.°¸°ÀÈ%Ð@PÐ	QÐRØ×"Ñ"Ø× Ñ ô €Jô  %Ÿ|š|Øˆaˆ&�5˜1•9˜a�. 5¨1¥9¨e°a­iÐ"8¸1¸eÀa½i¸.Ð	IÐJØ×"Ñ"Ø× Ñ ô ÷ �fˆZ×Ñ˜aÕ  " bÓ)ð	 ô " *¨jÓ9€Iä Ø�i % °dÐerôð r&   c                óÞ   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\        R\        R\        \        ,          R\         P                  /# )	r   r   Úsrc_boxÚdst_boxr   r   r   Úvalidate_boxesr   )r   r   r!   r"   r   )r#   s   "r$   r%   r%   @  s€   € ÷ kuñ kuÜ—,‘,ðkuä�\‰\ðkuô �\‰\ðkuô ð	kuô
 ðkuô ðkuô œT•Nðkuô ‡\�\ñkur&   c           	     ó”  € \         P                  P                  4       '       g   Ve   \        RRRR4       \	        V4      pV^ ,          P
                  ^ ,          ^ 8X  d   \        WVRW4V4      # V^ ,          V^ ,          ^ ,          8H  P                  4       '       d/   V^,          V^,          ^ ,          8H  P                  4       '       g!   \        RV^ ,           RV^,           R24      h\        V^ ,          ^ ,          P                  4       4      p\        V^,          ^ ,          P                  4       4      p	\        WW(V	3W4V4      # )	uc  Crop images by mapping a source box onto a destination box, whose size sets the output size.

``patches = crop_by_boxes(input_tensor, src_box, dst_box)`` takes images ``(B, C, H, W)`` and two boxes per image,
``(B, 4, 2)`` each (both ``(1, 4, 2)`` for all images), warps each image by the homography that maps ``src_box``
onto ``dst_box`` and returns the ``(B, C, h, w)`` window at destination pixels ``(0, 0)``..``(w - 1, h - 1)``, where
``(h, w)`` is the inclusive size of ``dst_box``. Every ``dst_box`` in the batch must have that same size, since the
output is one tensor, and a ``dst_box`` that does not start at ``(0, 0)`` shifts the crop by its offset, partly out
of the window. The size is read from the ``dst_box`` values on the host. When ``dst_box`` is the window
``(0, 0)``..``(w - 1, h - 1)`` itself and ``(h, w)`` is known, :func:`crop_and_resize` with ``size=(h, w)`` gives
the same crop without that read; it always places the destination box at the origin, so it cannot reproduce an
offset ``dst_box``. For volumes, use :func:`crop_by_boxes3d`.

Convention:
    - input: ``(B, C, H, W)``
    - ``src_box``/``dst_box``: ``(B, 4, 2)`` corner points in ``(x, y)`` order
      top-left, top-right, bottom-right, bottom-left â€” same convention as
      :func:`crop_and_resize`; ``dst_box`` determines the output resolution
    - a single box (batch size 1) broadcasts over a batch of images, but a single
      image does not broadcast over a batch of boxes; ``src_box`` and ``dst_box`` have the same batch size
    - an empty batch has no ``dst_box`` to read a size from and returns ``(0, C, 0, 0)``
    - a box axis of one pixel in one box but not in the other returns NaN (a meaningless finite value with
      ``mode='nearest'``), as in :func:`crop_and_resize`
      (`#4747 <https://github.com/kornia/kornia/issues/4747>`_)
    - a ``float16`` or ``bfloat16`` image is cropped in ``float32``, its homography solved and kept in
      ``float32``, and the patches rounded once to the image dtype

Args:
    input_tensor: the 2D image torch.Tensor with shape ``(B, C, H, W)``.
    src_box: a torch.Tensor with shape ``(B, 4, 2)`` containing the coordinates of the bounding boxes
        to be extracted, where each box is defined
        in the clockwise order: top-left, top-right, bottom-right and bottom-left.
        The coordinates must be in x, y order.
    dst_box: a torch.Tensor with shape ``(B, 4, 2)`` containing the coordinates of the bounding boxes
        to be placed, where each box is defined
        in the clockwise order: top-left, top-right, bottom-right and bottom-left.
        The coordinates must be in x, y order.
    mode: interpolation mode to calculate output values
      ``'bilinear'`` | ``'nearest'``.
    padding_mode: padding mode for outside grid values
      ``'zeros'`` | ``'border'`` | ``'reflection'``.
    align_corners: mode for grid_generation.
    validate_boxes: deprecated since kornia 0.9.1 and ignored; passing ``True`` or ``False`` emits a
      :class:`DeprecationWarning`, and the default ``None`` does not. The boxes are not validated, whatever
      its value: only the shapes of ``src_box`` and ``dst_box`` and the equal size of the ``dst_box`` boxes
      are checked.

Returns:
    the patches, with shape ``(B, C, h, w)`` for the size ``(h, w)`` of ``dst_box``.

Raises:
    AssertionError: if the boxes of ``dst_box`` differ in size.

See Also:
    - :func:`crop_and_resize`: takes the output size as ``size`` and places the box at the patch corners.
    - :func:`crop_by_transform_mat`: takes the sourceâ†’destination matrix itself.
    - :func:`crop_by_boxes3d`: the same for volumes and ``(B, 8, 3)`` boxes.

Examples:
    >>> input = torch.arange(16, dtype=torch.float32).reshape((1, 1, 4, 4))
    >>> src_box = torch.tensor([[
    ...     [1., 1.],
    ...     [2., 1.],
    ...     [2., 2.],
    ...     [1., 2.],
    ... ]])  # 1x4x2
    >>> dst_box = torch.tensor([[
    ...     [0., 0.],
    ...     [1., 0.],
    ...     [1., 1.],
    ...     [0., 1.],
    ... ]])  # 1x4x2
    >>> crop_by_boxes(input, src_box, dst_box, align_corners=True)
    tensor([[[[ 5.0000,  6.0000],
              [ 9.0000, 10.0000]]]])

Nz!crop_by_boxes(validate_boxes=...)z0.9.1zmThe argument has no effect: `crop_by_boxes` does not validate the boxes, whatever its value; stop passing it.zKCropping height, width and depth must be exact same in a batch. Got height z and width r+   ©rL   rL   )r   ÚjitÚis_scriptingr   r   r7   r>   Úallr8   r    Úitem)
r   rq   rr   r   r   r   rs   ÚbboxÚh_outÚw_outs
   &&&&&&&   r$   Úcrop_by_boxesr}   @  s#  € ôn �9‰9×!Ñ!×#Ò#¨Ò(BÜ!Ø/ØØðô		
ô /?¸wÓ.G€DØˆA…w‡}�}�QÕ˜1ÔÜ% l¸WÀfÈdÐboÓpÐpØ�!�W˜˜Q� �
Ñ"×'Ñ'×)Ò)¨t°A­w¸$¸q½'À!½*Ñ/D×.IÑ.I×.KÒ.KÜØYÐZ^Ð_`ÕZaÐYbÐbmÐnrÐstÕnuÐmvÐvwÐxó
ð 	
ô �T˜!•W˜Q•Z—_‘_Ó&Ó'€EÜ�T˜!•W˜Q•Z—_‘_Ó&Ó'€Eä! ,¸È%À.ÐRVÐfsÓtÐtr&   c                óê   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        \        \        3,          R\        R\        R\
        R\         P                  /# )	r   r   rq   rr   Úout_sizer   r   r   r   r   )r#   s   "r$   r%   r%   ®  sp   € ÷ <ñ <Ü—,‘,ð<ä�\‰\ð<ô �\‰\ð<ô ”Cœ�H�oð	<ô
 ð<ô ð<ô ð<ô ‡\�\ñ<r&   c           	     óÈ  € \        V P                  4      ^8w  d   \        RV P                   R24      hV P                  p\	        V 4      '       d   V P                  4       p VP                  V 4      pVP                  V 4      p\        V. R	O4       \        V. R	O4       \        VP                  VP                  8H  R4       \        P                  ! RR.RR.RR.RR...VP                  VP                  R7      pVR
,          P                  RR7      P                  VR
,          P                  RR7      P                  8H  VR,          P                  RR7      P                  VR,          P                  RR7      P                  8H  ,          VR
,          P                  RR7      P                  VR
,          P                  RR7      P                  8H  ,          VR,          P                  RR7      P                  VR,          P                  RR7      P                  8H  ,          p	\        P                  ! V	R,          W�4      p
\        P                  ! V	R,          W‚4      p\!        W«4      pVP#                  4       P%                  RR7      P%                  RR7      pVR,          VR,          ,
          ^ 8H  P'                  RR7      VR,          VR,          ,
          ^ 8H  P'                  RR7      ,          pW�( V,          ,          R,          p\)        \        P                  ! WñV4      V4      p\        P                  ! VVV4      p\+        WW4WVR7      P                  V4      # )a
  Crop images by boxes with the destination size already known as Python ints.

``crop_and_resize`` builds ``dst_box`` from ``size``, so it takes this path and never reads the box
values back from the device -- which also keeps it capturable by ``torch.onnx.export``.
r*   r+   z4Source data shape must match Destination data shape.g        g      ð?r,   ©Údimrb   ©ÚBÚ4Ú2)rK   rK   rL   r/   )rK   rK   rW   )rK   NNrU   rJ   )r5   r7   r8   r.   r
   Úfloatr9   r	   r   r   r<   r-   ÚmaxÚvaluesÚminrX   r   Úisfiniterx   Úanyr_   rd   )r   rq   rr   r   r   r   r   Ú	out_dtypeÚunitÚaxis_collinearÚsafe_src_boxÚsafe_dst_boxÚdst_trans_srcÚsolvedÚsize_oneÚfallbackÚextent_matrixs   &&&&&&&          r$   r>   r>   ®  sò  € ô ˆ<×ÑÓ !Ô#ÜÐXÐYe×YkÑYkÐXlÐlmÐnÓoÐoð
 ×"Ñ"€IÜ ×-Ò-Ø#×)Ñ)Ó+ˆð �j‰j˜Ó&€GØ�j‰j˜Ó&€Gä�w¢Ô0Ü�w¢Ô0Ü�—‘ '§-¡-Ñ/Ð1gÔhô
 �<Š<˜3 ˜* s¨C j°3¸°*¸sÀC¸jÐIÐJÐSZ×SaÑSaÐip×ivÑivÔw€Dà	�Õ	×	Ñ	 "Ð	Ó	%×	,Ñ	,°¸Õ0@×0DÑ0DÈÐ0DÓ0L×0SÑ0SÑ	SØ�7Õ×Ñ BÐÓ'×.Ñ.°'¸'Õ2B×2FÑ2FÈ2Ð2FÓ2N×2UÑ2UÑUõ	Wà�7Õ×Ñ BÐÓ'×.Ñ.°'¸'Õ2B×2FÑ2FÈ2Ð2FÓ2N×2UÑ2UÑUõ	Wð �7Õ×Ñ BÐÓ'×.Ñ.°'¸'Õ2B×2FÑ2FÈ2Ð2FÓ2N×2UÑ2UÑUõ	Wð ô —;’;˜~¨mÕ<¸dÓL€LÜ—;’;˜~¨mÕ<¸dÓL€LÜ";¸LÓ"W€Mð ×#Ñ#Ó%×)Ñ)¨bÐ)Ó1×5Ñ5¸"Ð5Ó=€FØ˜• ¨¥Õ.°1Ñ4×9Ñ9¸bÐ9ÓAÀgÈdÅmÐV]Ð^bÕVcÕFcÐhiÑEi×DnÑDnÐsuÐDnÓDvÕv€HØ '¨HÕ"4Õ5°}ÕE€Hô ,¬E¯KªK¸È4Ó,PÐRYÓZ€MÜ—K’K ¨-¸ÓG€Mä Ø XÀ|ôç�bˆƒmðr&   c                óÊ   € V ^8„  d   QhR\         P                  R\         P                  R\        \        \        3,          R\        R\        R\
        R\         P                  /# )r   r   rQ   r   r   r   r   r   r   )r#   s   "r$   r%   r%   í  sk   € ÷ Lñ LÜ—,‘,ðLä�|‰|ðLô ”Cœ�H�oðLô ð	Lô
 ðLô ðLô ‡\�\ñLr&   c           	     ó  € \         P                  ! VP                  V P                  ^ ,          RR4      V P                  V P
                  R7      pVP                  RR R8X  d   \        V VVVVVR7      # \        V VVVVVR7      pV# )uÎ	  Crop images by a sourceâ†’destination pixel matrix, affine or homography, into a given output size.

``patches = crop_by_transform_mat(input_tensor, transform, out_size)`` takes images ``(B, C, H, W)`` and a
sourceâ†’destination pixel matrix per image, affine ``(B, 2, 3)`` or homography ``(B, 3, 3)`` (a batch of 1 serves
every image), and returns the ``(B, C, h, w)`` destination window starting at pixel ``(0, 0)`` for
``out_size = (h, w)``. It calls :func:`~kornia.geometry.transform.warp_affine` for an affine matrix and
:func:`~kornia.geometry.transform.warp_perspective` for a homography, after casting the matrix to the image dtype
and expanding it to the batch: a float64 or integer matrix crops a float32 image, which those two reject, and a
batch-1 homography serves a batch, which ``warp_perspective`` alone does not allow. To build the matrix from boxes,
use :func:`crop_by_boxes` or :func:`crop_and_resize`; for volumes, :func:`crop_by_transform_mat3d`.

Convention:
    - input: ``(B, C, H, W)``; ``out_size`` is ``(h, w)``
    - ``transform`` is the sourceâ†’destination **pixel** transform, accepted as
      either ``(B, 2, 3)`` affine or ``(B, 3, 3)`` homogeneous; dispatch is
      by shape â€” ``(B, 2, 3)`` takes the cheaper :func:`warp_affine` path,
      while ``(B, 3, 3)`` takes :func:`warp_perspective` and uses the **full**
      matrix, so a non-trivial third (projective) row changes the output; an
      ``out_size`` dimension of ``1`` is handled like any other size

Args:
    input_tensor: the 2D image torch.Tensor with shape ``(B, C, H, W)``.
    transform: a perspective transformation matrix with shape ``(B, 3, 3)``, or an
      affine matrix with shape ``(B, 2, 3)`` that takes the cheaper warp_affine path.
    out_size: size of the output image (height, width).
    mode: interpolation mode to calculate output values
      ``'bilinear'`` | ``'nearest'``.
    padding_mode (str): padding mode for outside grid values
      ``'zeros'`` | ``'border'`` | ``'reflection'``.
    align_corners: mode for grid_generation.

Returns:
    the patches, with shape ``(B, C, h, w)``.

See Also:
    - :func:`warp_affine`: the affine warp it calls, with a ``fill_value`` for the padding.
    - :func:`warp_perspective`: the homography warp it calls, with a ``fill_value`` for the padding.
    - :func:`crop_by_boxes`: builds the homography from a source and a destination box.
    - :func:`crop_by_transform_mat3d`: the same for volumes, by ``(B, 3, 4)`` or ``(B, 4, 4)`` matrices.

r,   Nrb   r/   rc   )r   é   )r   Ú	as_tensorr=   r7   r-   r.   r   r   )r   rQ   r   r   r   r   r’   Úpatchess   &&&&&&  r$   rd   rd   í  sš   € ôd —O’OØ×Ñ˜×+Ñ+¨AÕ.°°BÓ7À×@SÑ@SÐ[g×[mÑ[mô€Mð ‡��r�sÐ˜vÔ%ÜØØØØØ%Ø'ô
ð 	
ô -ØØØØØ!Ø#ô€Gð €Nr&   c                ó  € V ^8„  d   QhR\         P                  R\         P                  R\        \        \        \        3,          ,          R\
        R\        \        ,          R\        R\
        R\         P                  /# )	r   r   rq   r   Úinterpolationr   Ú	antialiasÚshape_compensationr   )r   r   r   r   r    r!   r"   )r#   s   "r$   r%   r%   <  s   € ÷ Uñ UÜ—,‘,ðUä�\‰\ðUô ”5œœc˜•?Õ
#ðUô ð	Uô
 œD•>ðUô ðUô ðUô ‡\�\ñUr&   c           
     óH  a€ \        V . RO4       \        V. RO4       VR9  d   \        RV: R24      hV P                  w  rx p	\        P                  ! V\        P
                  R7      p
V
R,          pV
R,          ^,           pV
R,          pV
R,          ^,           pSe   \        4       '       d   \        WSV4      # SeF   \        4       '       d6   V^ 8”  d/   VR9   g   VR8X  d!   Vf   V'       g   VR8X  d   \        WSW44      # Se   S^ ,          S^,          3o\        P                  ! W¼WÞ.^ R7      P                  4       w  ppppV Uu. uF  p\        V) ^ 4      NK  	  ppV Uu. uF  p\        V) ^ 4      NK  	  ppV Uu. uF  p\        V^ 4      NK  	  upV Uu. uF  p\        V^ 4      NK  	  pppV Uu. uF  p\        V^ 4      NK  	  upV Uu. uF  p\        V^ 4      NK  	  ppp\        V4       Uu. uF0  pVR8g  ;'       d!    VV,          ^ 8„  ;'       g    VV,          ^ 8„  NK2  	  ppV^ 8”  Ed7   VP                  V^ ,          4      V8X  Ed   VP                  V^ ,          4      V8X  dü   VP                  V^ ,          4      V8X  dß   VP                  V^ ,          4      V8X  dÂ   VP                  V^ ,          4      V8X  d¥   VP                  V^ ,          4      V8X  dˆ   V R	V^ ,          V^ ,          1V^ ,          V^ ,          13,          pSeX   VP                  RR S8w  g   V^ ,          '       d5   VR8X  d   \        VSVVR
VR7      # \!        VSV^ ,          V^ ,          4      # Sf·   \#        V
4      w  ppV^ 8”  dY   VV^ ,          8g  P%                  4       VV^ ,          8g  P%                  4       ,          P'                  4       '       d   \        R4      hV^ 8”  dA   \)        V^ ,          P'                  4       4      \)        V^ ,          P'                  4       4      3MRoV^8”  d?   V P*                  '       d-   \        P,                  ! 4       '       d   V P/                  ^ 4      MRp\        V4       Uu. uFq  pVf7   V VV^,           1RVV,          VV,          1VV,          VV,          13,          M3VV,          RRVV,          VV,          1VV,          VV,          13,          NKs  	  ppV^ 8”  d‘   V P0                  P2                  R8w  dv   \%        V4      '       ge   \4        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      '       d%   \        P6                  ! V4      P9                  4       # Vf1   \        P:                  ! Wx.SO5RV P0                  RV P<                  / MRp. p\?        V4       Fz  w  ppVP                  RR S8w  g   VV,          '       d6   VR8X  d   \        VSVVR
VR7      pM\!        VSVV,          VV,          4      pVf   VPA                  V4       Ku  VVV&   K|  	  Vf%   \        P6                  ! V4      P9                  4       # V# u upi u upi u upi u upi u upi u upi u upi u upi )u‰  Crop axis-aligned boxes by integer slicing, then resize or pad each crop to a common size.

``patches = crop_by_indices(input_tensor, src_box, size)`` takes images ``(B, C, H, W)`` and one box per image,
``(B, 4, 2)``, slices each box out with integer indices and returns ``(B, C, h, w)`` for ``size = (h, w)``. Outside
graph export (see the notes) it slices by the top-left corner, the right edge (``x`` of vertex 1) and the bottom
edge (``y`` of vertex 3) of a box, and truncates float coordinates toward zero; without ``size`` it takes the size
from the box as :func:`~kornia.geometry.bbox.infer_bbox_shape` does, whose height reads ``y`` of vertex 2, and every
box must have the same size. A slice of another size than ``size``, from a box of another size or one clipped by the
image border, is resized (``shape_compensation='resize'``) or zero-padded or trimmed to it (``'pad'``).
The crop is differentiable with respect to the image, not the box: for sub-pixel, rotated or differentiable boxes,
use :func:`crop_and_resize`.

Convention:
    - input: ``(B, C, H, W)``; ``size`` is ``(h, w)`` if given, else inferred
      from ``src_box``; a single box does not broadcast over a batch of images
    - ``src_box``: ``(B, 4, 2)`` corner points in ``(x, y)`` order top-left,
      top-right, bottom-right, bottom-left â€” same convention as :func:`crop_and_resize`
    - unlike the other crop operators in this module: ``interpolation=`` (not
      ``mode=``), ``align_corners=None`` by default (not ``True``), and an
      ``antialias=False`` option
    - ``shape_compensation`` (``'resize'`` by default) applies whenever the cropped
      slice does not match ``size``, whether or not ``src_box`` is identical across
      the batch â€” each row's output depends only on its own box.
    - the part of a box outside the image is clipped on every side, a box that starts left of or above the
      image included, and ``shape_compensation`` then applies. With ``'pad'`` the padding goes on the side
      where the box overflowed, so every kept pixel stays at its position in the box.

.. note::
    Under :func:`torch.compile` a non-empty batch with ``size`` given, ``'bilinear'``,
    ``'bicubic'`` or ``'nearest'`` interpolation, ``antialias=False`` and
    ``shape_compensation='resize'`` is cropped by a gather that keeps the box coordinates
    on the device, so it traces with ``fullgraph=True`` and matches the eager result up to
    float rounding. Every other call keeps the eager path, which reads the box coordinates
    back to Python and breaks the graph. Graph export is described in the note below.

Args:
    input_tensor: the 2D image torch.Tensor with shape ``(B, C, H, W)``.
    src_box: a torch.Tensor with shape ``(B, 4, 2)`` containing the coordinates of the bounding boxes
        to be extracted, where each box is defined
        in the clockwise order: top-left, top-right, bottom-right and bottom-left.
        The coordinates must be in x, y order.
    size: output size. An auto resize or F.pad will be performed according to ``shape_compensation``
        if the cropped slice sizes are not exactly align `size`.
        If None, will auto-infer from src_box.
    interpolation:  algorithm used for upsampling: ``'nearest'`` | ``'nearest-exact'`` | ``'bilinear'`` |
        ``'bicubic'`` | ``'area'``.
    align_corners: interpolation flag.
    antialias: if True, then image will be filtered with Gaussian before downscaling.
        No effect for upscaling.
    shape_compensation: how to compensate when the cropped slice size differs from `size`: ``'resize'``
        resamples, while ``'pad'`` pads or trims. ``'F.pad'`` is a legacy alias for ``'pad'``.

Returns:
    The cropped torch.Tensor with shape ``(B, C, h, w)``, where
    ``(h, w)`` is ``size`` if given, otherwise the shape inferred
    from ``src_box``.

Raises:
    ValueError: if ``shape_compensation`` is not ``'resize'``, ``'pad'`` or ``'F.pad'``, or ``size`` is ``None``
        and the boxes differ in size.

See Also:
    - :func:`crop_and_resize`: resamples any four-corner box, differentiably with respect to its corners.
    - :class:`CenterCrop2D`: slices the central window with this function in its default mode, unless the size
      exceeds the input on an axis, where it zero-pads and slices directly.
    - :class:`~kornia.augmentation.RandomCrop`: random boxes, sliced with this function in its default mode, in an
      augmentation pipeline.

.. note::
    Under graph export (:func:`torch.export.export` / :func:`torch.onnx.export`) the box
    coordinates cannot be read back to Python, so the crop is captured as the same warp as
    :func:`crop_and_resize` (``align_corners=True``), which keeps the box coordinates dynamic.
    This needs ``size``: a box that is exactly ``size`` pixels (what
    :class:`~kornia.augmentation.RandomCrop` and :class:`CenterCrop2D` produce) is reproduced
    exactly, any other box is resampled to ``size`` with ``align_corners=True`` regardless of
    ``shape_compensation`` and ``align_corners``. Without ``size`` the eager path is kept: it
    reads the box coordinates back to Python, which breaks the graph under
    :func:`torch.compile` and is rejected by ``torch.export`` as data-dependent.

r   zE`shape_compensation` must be one of 'resize', 'pad', or 'F.pad'. Got r+   ©r.   rK   NÚnearestr�   .Úshort)r�   r   Úsiderž   z˜All boxes in the batch must have the same height and width when `size` is None. Please pass `size` explicitly when box dimensions vary across the batch.Úmpsc              3   óF   <"  € T F  qP                   RR S8H  x € K  	  R# 5i)r   Nrc   )r7   )Ú.0Úcropr   s   & €r$   Ú	<genexpr>Ú"crop_by_indices.<locals>.<genexpr>ù  s   øé € Ð;±F¨D—
‘
˜2˜3� 4Ö'³Fùs   ƒ!FTr-   r.   )r„   ÚCÚHÚWrƒ   )r   ÚpadzF.padrV   )rK   rW   rL   )rK   rL   rW   )rK   r™   rW   )ÚbilinearÚbicubicrc   ru   )!r	   r6   r7   r   rš   Úlongr   Ú_crop_by_indices_exportr   r   ÚstackÚtolistrˆ   ÚrangeÚcountr   Ú_pad_to_sizer   rŒ   ry   r    Úrequires_gradÚis_grad_enabledÚunbindr-   r2   rx   ÚcatÚ
contiguousÚemptyr.   Ú	enumerateÚappend)r   rq   r   r�   r   rž   rŸ   r„   r«   Ú_rF   Úx1Úx2Úy1Úy2Úx1lÚx2lÚy1lÚy2lÚvÚleftÚtopÚiÚshiftedÚoutÚhÚwÚrowsÚslicesÚcropsÚ_outs   &&f&&&&                        r$   Úcrop_by_indicesrÕ   <  sä  ø€ ôr �|Ò%9Ô:Ü�w¢Ô0ØÐ!;Ô;ÜØSÐTfÑSiÐijÐkó
ð 	
ð ×#Ñ#�J€Aˆ!ˆQô �/Š/˜'¬¯©Ô
4€CØ	ˆW�€BØ	ˆW�˜Õ	€BØ	ˆW�€BØ	ˆW�˜Õ	€BàÒœLŸNšNÜ& |¸dÀMÓRÐRàÒÜ�NŠNØ�ŒEØÐ5Ô5¸-È9Ô:TÐYfÒYnßØ (Ô*ô & l¸TÀ=Ó`Ð`ð ÒØ�Q•˜˜a�Ð!ˆô
 Ÿš b¨bÐ%5¸1Ô=×DÑDÓFÑ€Cˆˆc�3ñ !$Ó$¡˜1ŒC���AŽJ¡€DÐ$Ù"Ó
#™s˜!Œ3�ˆr�1Ž:™s€CÐ
#Ù#&Ó'¡3˜a”�A�q–	¡3Ñ'¹SÓ)A¹S¸¬#¨a°®)¹SˆÐ)A€CÙ#&Ó'¡3˜a”�A�q–	¡3Ñ'¹SÓ)A¹S¸¬#¨a°®)¹SˆÐ)A€CäW\Ð]^ÔW_Ó`ÑW_ÐRSÐ! XÑ-×MÐM°4¸µ7¸Q±;×3LÐ3LÀ#ÀaÅ&È1Á*ÒMÑW_€GÐ`ð
 	
ˆA�Ø�I‰I�c˜!•fÓ Õ"Ø�I‰I�c˜!•fÓ Ô"Ø�I‰I�c˜!•fÓ Ô"Ø�I‰I�c˜!•fÓ Ô"Ø�J‰J�t˜A•wÓ 1Ô$Ø�I‰I�c˜!•fÓ Ô"à˜3  A¥¨¨Q­ °°Qµ¸#¸a½&°Ð@ÕAˆØÒ §¡¨2¨3 °4Ô!7¸7À1¿:¼:Ø! XÔ-ÜØØØ"/Ø"/Ø Ø'ôð ô    T¨4°­7°C¸µFÓ;Ð;à‚|Ü Ó$‰ˆˆ1ØˆqŒ5�q˜A˜a�D‘y—o‘oÓ'¨1°°!µ©9¯/©/Ó*;Õ;×AÑA×CÒCÜð[óð ð 89¸1´u”�A�a•D—I‘I“KÓ ¤# a¨¥d§i¡i£kÓ"2Ñ3À&ˆð &'¨¤U¨|×/I×/IÐ/IÌe×NcÒNc×NeÒNeˆ<×Ñ˜qÔ!Ðko€Dô
 �q”ó	ñ ˆAð Š<ð 	�Q˜˜Q��Y  3 q¥6¨C°­F ?°C¸µF¸SÀ½V°OÐCÖDà�!�W�T˜1˜c !�f s¨1¥v˜o¨s°1­v¸¸A½¨Ð>Õ?ò	@ñ ð	 ð ð 	
ˆAŒØ×Ñ×$Ñ$¨Ô-Ü�G—’ß‹CÔ;±FÓ;�C�CŠCÔ;±FÓ;×;Ò;ä�yŠy˜Ó ×+Ñ+Ó-Ð-Ø\`Ò\hŒ%�+Š+�aÐ
X˜TÒ
X¨,×*=Ñ*=Ð
XÀ\×EWÑEWÒ
XÐnr€CØ "€EÜ˜VÖ$‰ˆˆ4Ø�:‰:�b�cˆ?˜dÔ" g¨a§j¤jØ! XÔ-ÜØØØ"/Ø"/Ø Ø'ô‘ô $ D¨$°°Qµ¸¸Q½Ó@�ØŠ;Ø�L‰L˜ÖàˆC�‹Fñ! %ð" ‚{Ü�yŠy˜Ó×*Ñ*Ó,Ð,Ø€Jùòe %ùÚ
#ùÚ'ùÒ)AùÚ'ùÒ)Aùâ`ùòLs=   ÅY<Å*ZÆZÆ!ZÆ=ZÇZÇ=ZÈZÈ"ZÒA7Zc          
      óž   € V ^8„  d   QhR\         P                  R\        \        \        3,          R\        R\        R\         P                  /# )r   r¨   r   rÊ   rË   r   )r   r   r   r    )r#   s   "r$   r%   r%     sI   € ÷ eñ e”u—|‘|ð e¬5´´c°­?ð eÄ#ð eÌCð eÔTY×T`ÑT`ñ er&   c           	      ó  € \        W!^,          4      \        W1^ ,          4      r2\        P                  ! WV^,          V P                  R,          ,
          V,
          W1^ ,          V P                  R,          ,
          V,
          .4      # )rW   r/   rc   )rŠ   ÚFr®   r7   )r¨   r   rÊ   rË   s   &&&&r$   r·   r·     sa   € ô �D˜q�'Ó"¤C¨°!­WÓ$5ˆ#Ü�5Š5�˜d 1�g¨¯
©
°2­Õ6¸Õ=¸sÈÅGÈdÏjÉjÐY[ÍnÕD\Ð_bÕDbÐcÓdÐdr&   c          
      ó²   € V ^8„  d   QhR\         P                  R\         P                  R\        \        \        3,          R\        R\         P                  /# )r   r   rq   r   r�   r   )r   r   r   r    r!   )r#   s   "r$   r%   r%     sN   € ÷ ñ Ü—,‘,ðä�\‰\ðô ””S��/ðô ð	ô
 ‡\�\ñr&   c           
      ód  € VR9  d   \        RV R24      hVw  rE\        P                  ! ^ ^ .V^,
          ^ .V^,
          V^,
          .^ V^,
          ...V P                  V P                  R7      P                  VP                  ^ ,          RR4      p\        WP                  V 4      WbVRRR7      # )	r¯   zR`crop_by_indices` can export with bilinear, nearest or bicubic interpolation. Got r+   r,   ÚzerosT)r   )r¯   r¢   r°   r/   )	r6   r   r<   r-   r.   r=   r7   r>   r9   )r   rq   r   r�   r?   r@   rB   s   &&&&   r$   r²   r²     sÃ   € ð Ð>Ô>ÜØ`ÐanÐ`oÐopÐqó
ð 	
ð �L€EÜ—’Øˆaˆ&�5˜1•9˜a�. 5¨1¥9¨e°a­iÐ"8¸1¸eÀa½i¸.Ð	IÐJØ×"Ñ"Ø× Ñ ô÷ �fˆW�]‰]˜1Õ˜r 2Ó&ð	 ô
 "Ø—j‘j Ó.°
À-ÐQXÐhlôð r&   c                   ó†   a a€ ] tR tRt oRtR]P                  P                  R3V3R lV 3R llltV3R lR lt	R	t
VtV ;t# )
r   i5  a  Crop the central window of each image to a given size, by slicing or resampling (module form).

Build ``cropper = CenterCrop2D(size)`` with an ``int`` or an ``(h, w)`` tuple, then ``out = cropper(input)`` returns
the central ``(B, C, h, w)`` windows of ``(B, C, H, W)`` images, at the offsets of :func:`center_crop`. The default
``cropping_mode='slice'`` slices with integer indices, through :func:`crop_by_indices`, or after zero-padding when
``size`` exceeds the input on an axis; ``'resample'`` samples the same windows, up to float rounding, by a
translation through :func:`~kornia.geometry.transform.warp_affine` with the ``resample`` mode. For one call, use
:func:`center_crop`; in an augmentation pipeline, :class:`~kornia.augmentation.CenterCrop`.

Convention:
    - ``align_corners`` (and ``resample``) only take effect when
      ``cropping_mode='resample'``; the default ``cropping_mode='slice'`` performs
      integer-index slicing and ignores both
    - See the convention block of :func:`~kornia.geometry.transform.center_crop`.

Args:
    size: Size ``(h, w)`` in pixels of the cropped region, or one ``int`` for both sides; a list raises
      ``TypeError``.
    align_corners: interpolation flag.
    resample: Resampling mode.
    cropping_mode: Cropping mode, "resample" or "slice".

Note:
    ``torch.jit.script`` compiles neither cropping mode, and ``torch.jit.trace`` records the crop offsets of the
    traced input size.

See Also:
    - :func:`center_crop`: the one-call form, which always resamples.
    - :func:`crop_by_indices`: the integer slicing of the default mode, for any axis-aligned box.
    - :class:`~kornia.augmentation.CenterCrop`: the same windows as an augmentation, for augmentation pipelines;
      it raises for a ``size`` larger than the input instead of padding.

TÚslicec          
      ó|   <€ V ^8„  d   QhRS[ S[S[S[S[3,          3,          RS[RS[ S[S[S[3,          RS[RR/# )r   r   r   ÚresampleÚcropping_moder   N)r   r    r   r"   r!   r   )r#   Ú__classdict__s   "€r$   r%   ÚCenterCrop2D.__annotate__X  s[   ø€ ÷ 
ñ 
á‘C™™s¡C˜x�Ð(Õ)ð
ñ ð
ñ ™™S¡(Ð*Õ+ð	
ñ
 ð
ð 
ñ
r&   c           
     ój  <€ \         SV `  4        \        V\        4      '       d   V^ ,          V^,          3V n        M7\        V\
        4      '       d
   W3V n        M\        R\        V4       R24      hV P                  w  rV\        P                  ! ^ ^ .V^,
          ^ .V^,
          V^,
          .^ V^,
          ...\        P                  R7      pV P                  RVP                  4       4       V P                  RV4       R\        P                  ! V4      RVRVR	V P                  R
R/V n        R# )rL   z9Invalid size type. Expected int or tuple[int, int]. Got: r+   r¡   rA   rB   rß   rà   r   r   r   rÛ   N)ÚsuperÚ__init__r0   r3   r   r    r1   r2   r   r<   r±   Úregister_bufferÚcloner   ÚgetÚflags)	Úselfr   r   rß   rà   r?   r@   rB   Ú	__class__s	   &&&&&   €r$   rå   ÚCenterCrop2D.__init__X  s  ø€ ô 	‰ÑÔÜ�dœE×"Ò"Ø˜a� $ q¥'Ð*ˆD�IÜ˜œc×"Ò"Ø˜ˆD�IäÐWÔX\Ð]aÓXbÐWcÐcdÐeÓfÐfà—y‘y‰ˆÜ—\’\ Q¨ F¨U°Q­Y¸¨N¸UÀQ½YÈÐPQÍ	Ð<RÐUVÐX]Ð`aÕXaÐTbÐ#cÐ"dÔlq×lvÑlvÔwˆ
Ø×Ñ˜\¨:×+;Ñ+;Ó+=Ô>Ø×Ñ˜\¨:Ô6ð œŸš XÓ.Ø˜]Ø˜]Ø�D—I‘IØ˜Gð
ˆŽ
r&   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   Úinputr   rH   )r#   rá   s   "€r$   r%   râ   t  s'   ø€ ÷ ?Yñ ?Y™UŸ\™\ð ?Y©e¯l©lñ ?Yr&   c           
     óD  € VP                   ^ ,          pV P                  w  r4VP                   RR w  rVV^,          V^,          r‡V^,          V^,          r©\        W¨,
          4      \        W—,
          4      rËW´,           ^,
          WÃ,           ^,
          ríW°P                  R&   WÀP                  R&   WÐP                  R&   WÀP                  R&   WÐP                  R&   WàP                  R&   W°P                  R&   WàP                  R&   V P                  R,          R8X  dÏ   \        V P                  P                  VRR4      P                  V4      V P                  P                  VRR4      P                  V4      4      pVP                  VRR4      p\        VVR,          V P                  V P                  R,          P                  P                  4       RV P                  R,          4      # V P                  R,          R8X  Ed   W58”  g   WF8”  d®   \        V) ^ 4      \        V) ^ 4      pp\        P                  ! VV\        V^,           V,
          ^ 4      V\        V^,           V,
          ^ 4      .4      pVRVV,           V^,           V,           1VV,           V^,           V,           13,          P                  4       # \!        WP                  P                  VRR4      P                  V4      V P                  R,          4      # \#        R	V P                  R,           R
24      h)a'  Crop the central region of each input image to ``self.size``.

Depending on ``cropping_mode``, the crop is produced either by
perspective-resampling (subpixel/interpolated) or by direct slicing.

Args:
    input: Image batch with shape ``(B, C, H, W)``, where
        :math:`B` is batch size, :math:`C` is channels, :math:`H` is
        source height, and :math:`W` is source width.

Returns:
    Center-cropped tensor with shape ``(B, C, h, w)``, where
    :math:`h` and :math:`w` are the requested crop height and width
    stored in ``self.size``.
Nrà   rß   rÛ   r   rÝ   .r   zNot supported type: r+   rc   )rL   rL   rL   )rL   rL   rW   )rL   rW   rL   )rL   rW   rW   )rL   r   rL   )rL   r   rW   )rL   r™   rL   )rL   r™   rW   r/   )rK   rN   rK   )r7   r   r    rA   ré   rR   r=   r9   rB   rd   ÚnameÚlowerrˆ   rØ   r®   r¼   rÕ   ÚNotImplementedError)rê   rî   Ú
batch_sizer?   r@   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   rQ   rÊ   rË   Úpaddeds   &&                 r$   ÚforwardÚCenterCrop2D.forwardt  s©  € ð  —[‘[ •^ˆ
à—y‘y‰ˆØ—{‘{ 2 3Ð'‰ˆà!&¨¥¨E°A­I�JØ!&¨¥¨E°A­I�Jä˜zÕ6Ó7¼¸ZÕ=TÓ9U�Ø•¨Õ*¨G­O¸aÕ,?ˆuð $+�‰˜Ñ Ø#*�‰˜Ñ Ø#(�‰˜Ñ Ø#*�‰˜Ñ Ø#(�‰˜Ñ Ø#(�‰˜Ñ Ø#*�‰˜Ñ Ø#(�‰˜Ñ à�:‰:�oÕ&¨*Ô4Ü)Ø—‘×&Ñ& z°2°rÓ:×=Ñ=¸eÓDØ—‘×&Ñ& z°2°rÓ:×=Ñ=¸eÓDóˆIð "×(Ñ(¨°R¸Ó<ˆIä(ØØ˜(Õ#Ø—	‘	Ø—
‘
˜:Õ&×+Ñ+×1Ñ1Ó3ØØ—
‘
˜?Õ+óð ð �:‰:�oÕ&¨'Õ1ØŒ} ¤ô    ¨!Ó,¬c°7°(¸AÓ.>�c�ÜŸš˜u t¬S°¸µ¸UÕ1BÀAÓ-FÈÌSÐQVÐYZÕQZÐ]bÕQbÐdeÓMfÐ&gÓh�Ø˜c 7¨S¥=°5¸1µ9¸sµ?Ð#BÀGÈdÅNÐUZÐ]^ÕU^ÐaeÕUeÐDeÐeÕf×qÑqÓsÐsÜ" 5¯/©/×*@Ñ*@ÀÈRÐQSÓ*T×*WÑ*WÐX]Ó*^Ð`d×`jÑ`jÐkqÕ`rÓsÐsä!Ð$8¸¿¹ÀOÕ9TÐ8UÐUVÐ"WÓXÐXr&   )ré   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚBILINEARrð   rå   rõ   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)rë   rá   s   @@r$   r   r   5  s>   ù‡ € ñ ðJ #Ø.6×.?Ñ.?×.DÑ.DØ$÷
õ 
÷8?Y÷ ?Yð ?Yr&   )r   ro   rC   r}   rÕ   rd   )r¯   rÛ   T)r¯   rÛ   TN)r¯   rÛ   F)Nr¯   NFr   ),rû   Útypingr   r   r   r   Útorch.nn.functionalr   Ú
functionalrØ   Úkornia.constantsr   Úkornia.core._compatr   Úkornia.core.checkr   r	   Úkornia.core.utilsr
   r   r   Úkornia.geometry.bboxr   Úkornia.geometry.transform._cropr   Úaffwarpr   Úimgwarpr   r   r   Ú__all__rC   rR   r_   ro   r}   r>   rd   rÕ   r·   r²   ÚModuler   © r&   r$   Ú<module>r     s–   ðñ$÷4 *Ñ )ã ß Ð Ý å %Ý 9ß >ß RÑ RÝ 1Ý Bå ß MÑ Mò€÷lõ^õ÷0e÷Pku÷\<÷~L÷^Uõpeõô2~Y�2—9‘9ö ~Yr&   