+
    åûj™Z  ã                  ó  € ^ RI Ht ^ RIHt ^ RIHtHtHt ^ RIt^ RI	H
t
Ht ^ RIt^ RIHt ^ RIHt ^ RIHtHtHtHtHtHt ^ R	IHt ^ R
IHtHtHt ]t]t ]PB                  ^]PD                  ^]PF                  ^/t$R R lt% ! R R4      t&R# )é    )Úannotations)ÚPath)ÚAnyÚOptionalÚUnionN)Úfrom_dlpackÚ	to_dlpack)Úare_checks_enabled)ÚValueCheckError)ÚKORNIA_CHECK_IMAGE_LAYOUTÚChannelsOrderÚ
ColorSpaceÚImageLayoutÚ	ImageSizeÚPixelFormat)Úimage_to_string)ÚImageLoadTypeÚ
load_imageÚwrite_imagec               ó    € V ^8„  d   QhRRRR/# )é   ÚchannelsÚintÚreturnr   © )Úformats   "ÚNC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\image\image.pyÚ__annotate__r   1   s   € ÷ Uñ U 3ð U¨:ñ Uó    c                ó‚   € ^\         P                  ^\         P                  /P                  V \         P                  4      # )zSLabel an image by its channel count: 1 is GRAY, 3 is RGB, anything else is UNKNOWN.)r   ÚGRAYÚRGBÚgetÚUNKNOWN)r   s   &r   Ú_default_color_spacer%   1   s,   € àŒz�‰ ¤:§>¡>Ð2×6Ñ6°xÄ×ASÑASÓTÐTr   c                  ó  € ] tR t^6tRtR R ltR R ltR8R R lltR	 R
 lt]	R R l4       t
]	R R l4       t]	R R l4       t]	R R l4       t]	R R l4       t]	R R l4       t]	R R l4       t]	R R l4       t]	R R l4       t]	R R l4       t]	R R  l4       tR! R" ltR# R$ ltR% R& ltR' R( lt]R]P6                  3R) R* ll4       tR+ R, lt]R]P<                  3R- R. ll4       tR/ R0 lt ]R1 R2 l4       t!R3 R4 lt"R9R5 R6 llt#R7t$R# ):ÚImagea^  Hold one image tensor with its layout and color space, checked against the data.

``img = Image(data, pixel_format, layout)`` wraps one unbatched image tensor, ``(C, H, W)`` or ``(H, W, C)`` as
``layout.channels_order`` says, and raises when the shape, the bit depth or the color space does not fit the data.
:meth:`from_numpy`, :meth:`from_dlpack` and :meth:`from_file` build the layout and the pixel format for you.
kornia's other functions take plain channels-first tensors: pass them ``img.data`` of a ``CHANNELS_FIRST`` image,
or ``img.data[None]`` where they take a batch.

.. warning::

    This API is experimental and might suffer changes in the future.

Convention:
    - A batch or an ``(H, W)`` tensor raises ``ShapeError``.
    - :meth:`from_numpy`, :meth:`to_numpy`, :meth:`from_dlpack` and :meth:`to_dlpack` share memory with the
      array or capsule of a CPU image, except that :meth:`to_numpy` copies bfloat16 data to float32 because
      NumPy has no bfloat16 dtype. :meth:`to_numpy` and :meth:`to_dlpack` return the stored layout, so an
      image from :meth:`from_file` gives ``(C, H, W)``. Neither the array nor the capsule carries the layout
      or the color space: :meth:`from_numpy` reads ``(H, W, C)`` and :meth:`from_dlpack` reads
      ``(C, H, W)`` unless ``channels_order`` says otherwise, and both label the color space by channel count
      unless ``color_space`` is given. Pass ``img.pixel_format.color_space`` and ``img.channels_order`` to read an
      exported image back.
    - :meth:`to_gray`, :meth:`to_rgb` and :meth:`to_bgr` return the image itself when it is already in that color
      space, an image with new data when it is in another of the three, and raise ``ValueError`` for
      ``UNKNOWN``. Converting RGB or BGR to gray requires ``uint8`` or a floating dtype supported by
      :func:`~kornia.color.rgb_to_grayscale`; other integer dtypes, such as ``uint16``, raise ``TypeError`` even
      though ``Image`` can hold them. :meth:`to`, :meth:`float` and :meth:`clone` return a new ``Image`` and
      leave this one unchanged.

Args:
    data: a torch.Tensor containing the image data.
    pixel_format: the pixel format of the image.
    layout: a dataclass containing the image layout information.

See Also:
    - :func:`~kornia.io.load_image`: loads a file as a plain tensor, with a choice of
      :class:`~kornia.io.ImageLoadType`; :meth:`from_file` always loads ``RGB8``.
    - :func:`image_to_tensor`: converts a NumPy array to a channels-first tensor without the container.
    - :class:`ImageLayout`: the shape description the constructor checks.
    - :class:`PixelFormat`: the value description the constructor checks.

Examples:
    >>> # from a torch.tensor
    >>> data = torch.randint(0, 255, (3, 4, 5), dtype=torch.uint8)  # CxHxW
    >>> pixel_format = PixelFormat(
    ...     color_space=ColorSpace.RGB,
    ...     bit_depth=8,
    ... )
    >>> layout = ImageLayout(
    ...     image_size=ImageSize(4, 5),
    ...     channels=3,
    ...     channels_order=ChannelsOrder.CHANNELS_FIRST,
    ... )
    >>> img = Image(data, pixel_format, layout)
    >>> assert img.channels == 3

    >>> # from a numpy array (like opencv)
    >>> data = np.ones((4, 5, 3), dtype=np.uint8)  # HxWxC
    >>> img = Image.from_numpy(data, color_space=ColorSpace.RGB)
    >>> assert img.channels == 3
    >>> assert img.width == 5
    >>> assert img.height == 4

c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   Údataútorch.TensorÚpixel_formatr   Úlayoutr   r   ÚNoner   )r   s   "r   r   ÚImage.__annotate__x   s)   € ÷ &ñ &˜\ð &¸ð &Èkð &Ð^bñ &r   c           	     ó  € \        W4       \        4       '       dÕ   ^VP                  4       ,          pVP                  V8w  d8   \	        RVP                   RV RVP
                   R2VP                  WD3R7      h\        P                  VP                  4      pVeS   VP                  V8w  dB   \	        RVP                  P                   RV R	VP                   R
2VP                  WU3R7      hWn        W n        W0n        R# )aƒ  Image constructor.

Like the other kornia checks, the layout and pixel-format checks are skipped after
``kornia.core.check.disable_checks()``.

Args:
    data: a torch.Tensor containing the image data.
    pixel_format: the pixel format of the image.
    layout: a dataclass containing the image layout information.

Raises:
    ShapeError: if ``data`` does not have the shape ``layout`` describes. It is also a ``ValueError``.
    ValueCheckError: if ``pixel_format.bit_depth`` is not ``8 * data.element_size()`` (also a ``ValueError``).
    ValueCheckError: if the color space does not match the channel count. It is also a ``ValueError``.

z)Invalid bit depth: the pixel format says z  bits but the data is stored in z bits (z).)Úactual_valueÚexpected_rangeNzInvalid color space: z needs z channel(s) but the layout has z2. Use ColorSpace.UNKNOWN for other channel counts.)r   r
   Úelement_sizeÚ	bit_depthr   ÚdtypeÚ_CHANNELS_OF_COLOR_SPACEr#   Úcolor_spacer   ÚnameÚ_dataÚ_pixel_formatÚ_layout)Úselfr)   r+   r,   Ústorage_bitsÚexpected_channelss   &&&&  r   Ú__init__ÚImage.__init__x   s  € ô" 	" $Ô/Ü×ÒØ˜t×0Ñ0Ó2Õ2ˆLØ×%Ñ%¨Ô5Ü%Ø?À×@VÑ@VÐ?Wð XØ&˜ w¨t¯z©z¨l¸"ð>à!-×!7Ñ!7Ø$0Ð#?ô	ð ô !9× <Ñ <¸\×=UÑ=UÓ VÐØ Ò,°·±ÐDUÔ1UÜ%Ø+¨L×,DÑ,D×,IÑ,IÐ+JÈ'ÐRcÐQdð e&Ø&,§o¡oÐ%6Ð6hðjà!'§¡Ø$5Ð#Iô	ð ð Œ
Ø)ÔØŽr   c               ó   € V ^8„  d   QhRR/# )r   r   Ústrr   )r   s   "r   r   r.       s   € ÷ eñ e˜#ñ er   c                	óT   € R V P                    RV P                   RV P                   2# )zImage data: z
Pixel Format: z

 Layout: )r)   r+   r,   ©r;   s   &r   Ú__repr__ÚImage.__repr__    s/   € Ø˜dŸi™i˜[Ð(8¸×9JÑ9JÐ8KÈ;ÐW[×WbÑWbÐVcÐdÐdr   Nc               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚdevicezUnion[str, torch.device, None]r4   zUnion[torch.dtype, None]r   r'   r   )r   s   "r   r   r.   ¤   s$   € ÷ 6ñ 6Ð7ð 6ÐG_ð 6Ðkpñ 6r   c                ó  € Ve$   \        V\        P                  4      '       d   TRrV P                  P	                  W4      p\        V P                  P                  VP                  4       ^,          R7      p\        W4V P                  4      # )a   Return the image on ``device`` and with ``dtype``, like :meth:`torch.Tensor.to`.

The image itself is not changed; assign the result (``img = img.to(...)``). The pixel format's ``bit_depth``
follows the new dtype.

Args:
    device: the device to move the image to.
    dtype: the data type to cast the image to.

Returns:
    Image: the image on the given device and with the given dtype.

Raises:
    ValueCheckError: if the image was built with checks disabled and its color space does not fit its channels.

N©r6   r3   )Ú
isinstanceÚtorchr4   r)   Útor   r+   r6   r2   r'   r,   )r;   rG   r4   r)   r+   s   &&&  r   rL   ÚImage.to¤   sl   € ð" Ò¤*¨V´U·[±[×"AÒ"AØ" D�6Ø�y‰y�|‰|˜FÓ*ˆÜ"¨t×/@Ñ/@×/LÑ/LÐX\×XiÑXiÓXkÐnoÕXoÔpˆÜ�T¨¯©Ó5Ð5r   c               ó   € V ^8„  d   QhRR/# ©r   r   r'   r   )r   s   "r   r   r.   ¼   s   € ÷ Hñ H�uñ Hr   c                ót   € \        V P                  P                  4       V P                  V P                  4      # )zReturn a copy of the image.)r'   r)   Úcloner+   r,   rC   s   &r   rQ   ÚImage.clone¼   s&   € ä�T—Y‘Y—_‘_Ó&¨×(9Ñ(9¸4¿;¹;ÓGÐGr   c               ó   € V ^8„  d   QhRR/# )r   r   r*   r   )r   s   "r   r   r.   Á   s   € ÷ ñ �lñ r   c                ó   € V P                   # )z(Return the underlying torch.Tensor data.)r8   rC   s   &r   r)   Ú
Image.dataÀ   s   € ð �z‰zÐr   c               ó   € V ^8„  d   QhRR/# )r   r   ztuple[int, ...]r   )r   s   "r   r   r.   Æ   s   € ÷ ñ �ñ r   c                ó.   € V P                   P                  # )zReturn the image shape.)r)   ÚshaperC   s   &r   rX   ÚImage.shapeÅ   ó   € ð �y‰y�‰Ðr   c               ó   € V ^8„  d   QhRR/# )r   r   ztorch.dtyper   )r   s   "r   r   r.   Ë   s   € ÷ ñ �{ñ r   c                ó.   € V P                   P                  # )zReturn the image data type.)r)   r4   rC   s   &r   r4   ÚImage.dtypeÊ   rZ   r   c               ó   € V ^8„  d   QhRR/# )r   r   ztorch.devicer   )r   s   "r   r   r.   Ð   s   € ÷  ñ  ˜ñ  r   c                ó.   € V P                   P                  # )zReturn the image device.)r)   rG   rC   s   &r   rG   ÚImage.deviceÏ   s   € ð �y‰y×ÑÐr   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r.   Õ   s   € ÷ "ñ "˜kñ "r   c                ó   € V P                   # )zReturn the pixel format.)r9   rC   s   &r   r+   ÚImage.pixel_formatÔ   s   € ð ×!Ñ!Ð!r   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r.   Ú   s   € ÷ ñ ˜ñ r   c                ó   € V P                   # )zReturn the image layout.)r:   rC   s   &r   r,   ÚImage.layoutÙ   s   € ð �|‰|Ðr   c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r   r   r.   ß   s   € ÷ $ñ $˜#ñ $r   c                ó.   € V P                   P                  # )z(Return the number channels of the image.)r,   r   rC   s   &r   r   ÚImage.channelsÞ   s   € ð �{‰{×#Ñ#Ð#r   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r.   ä   s   € ÷ &ñ &˜Iñ &r   c                ó.   € V P                   P                  # )zReturn the image size.)r,   Ú
image_sizerC   s   &r   rm   ÚImage.image_sizeã   s   € ð �{‰{×%Ñ%Ð%r   c               ó   € V ^8„  d   QhRR/# rh   r   )r   s   "r   r   r.   é   s   € ÷ 2ñ 2˜ñ 2r   c                óT   € \        V P                  P                  P                  4      # )z)Return the image height (number of rows).)r   r,   rm   ÚheightrC   s   &r   rq   ÚImage.heightè   s   € ô �4—;‘;×)Ñ)×0Ñ0Ó1Ð1r   c               ó   € V ^8„  d   QhRR/# rh   r   )r   s   "r   r   r.   î   s   € ÷ 1ñ 1�sñ 1r   c                óT   € \        V P                  P                  P                  4      # )z+Return the image width (number of columns).)r   r,   rm   ÚwidthrC   s   &r   ru   ÚImage.widthí   s   € ô �4—;‘;×)Ñ)×/Ñ/Ó0Ð0r   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r.   ó   s   € ÷ *ñ * ñ *r   c                ó.   € V P                   P                  # )zReturn the channels order.)r,   Úchannels_orderrC   s   &r   ry   ÚImage.channels_orderò   s   € ð �{‰{×)Ñ)Ð)r   c               ó   € V ^8„  d   QhRR/# rO   r   )r   s   "r   r   r.   ø   s   € ÷ ,ñ ,�uñ ,r   c                óB   € V P                  \        P                  R7      # )z½Return the image as float32 without rescaling; the image itself is not changed.

A ``uint8`` 255 becomes 255.0, outside the :math:`[0, 1]` range that :meth:`print` reads for a float image.
)r4   )rL   rK   Úfloat32rC   s   &r   ÚfloatÚImage.floatø   s   € ð
 �w‰wœUŸ]™]ˆwÓ+Ð+r   c               ó   € V ^8„  d   QhRR/# rO   r   )r   s   "r   r   r.   ÿ   s   € ÷ .ñ .˜ñ .r   c                óê  € V P                   P                  pV P                  pV\        P                  8X  d   V # V P
                  P                  \        P                  8H  pV'       d9   VP                  ^8X  d   VP                  ^ ^^^4      MVP                  ^^ ^4      pV\        P                  8X  d!   \        P                  P                  V4      pMCV\        P                  8X  d!   \        P                  P!                  V4      pM\#        RV 24      hV'       dd   VP                  ^8X  d   VP                  ^ ^^^4      pM=VP                  ^8X  d   VP                  ^^^ 4      pM\#        RVP$                   24      h\'        \        P                  V P                   P(                  R7      p\+        V P
                  P,                  ^V P
                  P                  R7      p\/        WEV4      # )zConvert the image to grayscale.z.Unsupported source color space for to_gray(): z-Unexpected shape after grayscale conversion: rI   ©r   ry   )r9   r6   r8   r   r!   r:   ry   r   ÚCHANNELS_LASTÚndimÚpermuter"   ÚkorniaÚcolorÚrgb_to_grayscaleÚBGRÚbgr_to_grayscaleÚ
ValueErrorrX   r   r3   r   rm   r'   ©r;   Úsrcr)   Úis_channels_lastÚoutÚnew_pfÚ
new_layouts   &      r   Úto_grayÚImage.to_grayÿ   sx  € à× Ñ ×,Ñ,ˆØ�z‰zˆà”*—/‘/Ô!ØˆKàŸ<™<×6Ñ6¼-×:UÑ:UÑUÐßØ/3¯y©y¸A¬~�4—<‘<  1 a¨Ô+À4Ç<Á<ÐPQÐSTÐVWÓCXˆDð ”*—.‘.Ô Ü—,‘,×/Ñ/°Ó5‰CØ”J—N‘NÔ"Ü—,‘,×/Ñ/°Ó5‰CäÐMÈcÈUÐSÓTÐTçØ�x‰x˜1Œ}Ø—k‘k ! Q¨¨1Ó-‘Ø—‘˜Q”Ø—k‘k ! Q¨Ó*‘ä Ð#PÐQT×QZÑQZÐP[Ð!\Ó]Ð]ä¬¯©ÀD×DVÑDV×D`ÑD`ÔaˆÜ  §¡×!8Ñ!8À1ÐUY×UaÑUa×UpÑUpÔqˆ
Ü�S *Ó-Ð-r   c               ó   € V ^8„  d   QhRR/# rO   r   )r   s   "r   r   r.     s   € ÷ .ñ .˜ñ .r   c                ó®  € V P                   P                  pV P                  pV\        P                  8X  d   V # V P
                  P                  \        P                  8H  pV'       d9   VP                  ^8X  d   VP                  ^ ^^^4      MVP                  ^^ ^4      pV\        P                  8X  d!   \        P                  P                  V4      pMPV\        P                  8X  d.   VP                  ^8X  d   VR. ROR3,          MV. ROR3,          pM\!        RV 24      hV'       d9   VP                  ^8X  d   VP                  ^ ^^^4      MVP                  ^^^ 4      p\#        \        P                  V P                   P$                  R7      p\'        V P
                  P(                  ^V P
                  P                  R7      p\+        WEV4      # )zConvert the image to RGB.ºNNN.z-Unsupported source color space for to_rgb(): rI   r‚   ©r   é   r   )r9   r6   r8   r   r"   r:   ry   r   rƒ   r„   r…   r!   r†   r‡   Úgrayscale_to_rgbr‰   r‹   r   r3   r   rm   r'   rŒ   s   &      r   Úto_rgbÚImage.to_rgb  s`  € à× Ñ ×,Ñ,ˆØ�z‰zˆà”*—.‘.Ô ØˆKàŸ<™<×6Ñ6¼-×:UÑ:UÑUÐßØ/3¯y©y¸A¬~�4—<‘<  1 a¨Ô+À4Ç<Á<ÐPQÐSTÐVWÓCXˆDà”*—/‘/Ô!Ü—,‘,×/Ñ/°Ó5‰CØ”J—N‘NÔ"Ø-1¯Y©Y¸!¬^�$�qš) SÐ(Ö)ÀÂiÐQTÀnÕAU‰CäÐLÈSÈEÐRÓSÐSçØ-0¯X©X¸¬]�#—+‘+˜a  A qÔ)ÀÇÁÈAÈqÐRSÓ@TˆCä¬¯©À4×CUÑCU×C_ÑC_Ô`ˆÜ  §¡×!8Ñ!8À1ÐUY×UaÑUa×UpÑUpÔqˆ
Ü�S *Ó-Ð-r   c               ó   € V ^8„  d   QhRR/# rO   r   )r   s   "r   r   r.   9  s   € ÷ .ñ .˜ñ .r   c                ó  € V P                   P                  pV P                  pV\        P                  8X  d   V # V P
                  P                  \        P                  8H  pV'       d9   VP                  ^8X  d   VP                  ^ ^^^4      MVP                  ^^ ^4      pV\        P                  8X  dM   \        P                  P                  V4      pVP                  ^8X  d   VR. ROR3,          MV. ROR3,          pMPV\        P                  8X  d.   VP                  ^8X  d   VR. ROR3,          MV. ROR3,          pM\!        RV 24      hV'       d9   VP                  ^8X  d   VP                  ^ ^^^4      MVP                  ^^^ 4      p\#        \        P                  V P                   P$                  R7      p\'        V P
                  P(                  ^V P
                  P                  R7      p\+        WVV4      # )zConvert the image to BGR.r–   .z-Unsupported source color space for to_bgr(): rI   r‚   r—   )r9   r6   r8   r   r‰   r:   ry   r   rƒ   r„   r…   r!   r†   r‡   r™   r"   r‹   r   r3   r   rm   r'   )r;   r�   r)   rŽ   Úrgb_datar�   r�   r‘   s   &       r   Úto_bgrÚImage.to_bgr9  sŠ  € à× Ñ ×,Ñ,ˆØ�z‰zˆà”*—.‘.Ô ØˆKàŸ<™<×6Ñ6¼-×:UÑ:UÑUÐßØ/3¯y©y¸A¬~�4—<‘<  1 a¨Ô+À4Ç<Á<ÐPQÐSTÐVWÓCXˆDà”*—/‘/Ô!Ü—|‘|×4Ñ4°TÓ:ˆHØ19·±À!Ô1C�(˜1ši¨Ð,Ö-ÈÒR[Ð]`ÐR`ÕIa‰CØ”J—N‘NÔ"Ø-1¯Y©Y¸!¬^�$�qš) SÐ(Ö)ÀÂiÐQTÀnÕAU‰CäÐLÈSÈEÐRÓSÐSçØ-0¯X©X¸¬]�#—+‘+˜a  A qÔ)ÀÇÁÈAÈqÐRSÓ@TˆCä¬¯©À4×CUÑCU×C_ÑC_Ô`ˆÜ  §¡×!8Ñ!8À1ÐUY×UaÑUa×UpÑUpÔqˆ
Ü�S *Ó-Ð-r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r)   Ú
np_ndarrayr6   úOptional[ColorSpace]ry   r   r   r'   r   )r   s   "r   r   r.   U  s8   € ÷ 2Añ 2Aàð2Að *ð2Að &ð	2Að
 
ñ2Ar   c                ó”  € VP                   ^8X  d(   V\        P                  8X  d
   VR,          MVR,          pV\        P                  8X  dD   \        VP                  ^ ,          VP                  ^,          R7      pVP                  ^,          pMcV\        P
                  8X  dD   \        VP                  ^,          VP                  ^,          R7      pVP                  ^ ,          pM\        R4      hVf   \        V4      p\        W!P                  ^,          R7      p\        WEVR7      pV ! \        P                  ! V4      Wg4      # )a  Construct an ``Image`` from a numpy array, sharing its memory.

Args:
    data: a numpy array containing the image data.
    color_space: the color space of the image. If ``None``, a 1-channel array is ``GRAY``, a 3-channel
        array is ``RGB`` and any other channel count is ``UNKNOWN``. An explicit color space that does not
        match the channel count raises.
    channels_order: what dimension the channels are in the image torch.Tensor.

Raises:
    ValueError: if ``channels_order`` is neither ``CHANNELS_LAST`` nor ``CHANNELS_FIRST``.
    ValueCheckError: if an explicit ``color_space`` does not match the channel count (also a ``ValueError``).
    ShapeError: if ``data`` has more than three dimensions. It is also a ``ValueError``.
    IndexError: if ``data`` has fewer than two dimensions.

Example:
    >>> data = np.ones((4, 5, 3), dtype=np.uint8)  # HxWxC
    >>> img = Image.from_numpy(data, color_space=ColorSpace.RGB)
    >>> assert img.channels == 3
    >>> assert img.width == 5
    >>> assert img.height == 4

N©rq   ru   úAchannels_order must be either `CHANNELS_LAST` or `CHANNELS_FIRST`rI   ©rm   r   ry   ).N)r„   r   rƒ   r   rX   ÚCHANNELS_FIRSTr‹   r%   r   Úitemsizer   rK   Ú
from_numpy)Úclsr)   r6   ry   rm   r   r+   r,   s   &&&&    r   rª   ÚImage.from_numpyT  sõ   € ð< �9‰9˜Œ>à&4¼×8SÑ8SÔ&S�4˜	–?ÐY]Ð^bÕYcˆDØœ]×8Ñ8Ô8Ü"¨$¯*©*°Q­-¸t¿z¹zÈ!½}ÔMˆJØ—z‘z !•}‰HØœ}×;Ñ;Ô;Ü"¨$¯*©*°Q­-¸t¿z¹zÈ!½}ÔMˆJØ—z‘z !•}‰HäÐ`ÓaÐaàÒÜ.¨xÓ8ˆKä"¨{ÇmÁmÐVWÕFWÔXˆô ¨
ÐVdÔeˆñ ”5×#Ò# DÓ)¨<Ó@Ð@r   c               ó   € V ^8„  d   QhRR/# )r   r   r¢   r   )r   s   "r   r   r.   ‰  s   € ÷ 	ñ 	˜*ñ 	r   c                óÐ   € V P                   P                  4       P                  4       pVP                  \        P
                  8X  d   VP                  4       pVP                  4       # )zìReturn the image data as a numpy array on the CPU, in the stored layout.

The array shares memory with CPU data whose dtype NumPy supports. Bfloat16 data is copied to float32,
preserving its values, because NumPy has no bfloat16 dtype.
)r)   ÚcpuÚdetachr4   rK   Úbfloat16r~   Únumpy)r;   r)   s   & r   Úto_numpyÚImage.to_numpy‰  sC   € ð �y‰y�}‰}‹×%Ñ%Ó'ˆØ�:‰:œŸ™Ô'Ø—:‘:“<ˆDØ�z‰z‹|Ðr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r)   ÚDLPackr6   r£   ry   r   r   r'   r   )r   s   "r   r   r.   •  s2   € ÷ 70ñ 70àð70ð *ð70ð &ð	70ð
 
ñ70r   c                ó8  € V\         P                  \         P                  39  d   \        R4      h\	        V4      pV\         P                  8X  dD   \        VP                  ^,          VP                  ^,          R7      pVP                  ^ ,          pMB\        VP                  ^ ,          VP                  ^,          R7      pVP                  ^,          pVf   \        V4      p\        W$P                  4       ^,          R7      p\        WVVR7      pV ! WGV4      # )aÆ  Construct an ``Image`` from a DLPack capsule, sharing its memory.

A capsule carries neither the layout nor the color space, so read ``img.to_dlpack()`` back with
``Image.from_dlpack(capsule, img.pixel_format.color_space, img.channels_order)``.

Args:
    data: a DLPack capsule from numpy, tvm or jax, holding a ``(C, H, W)`` image, or ``(H, W, C)`` with
        ``channels_order=CHANNELS_LAST``.
    color_space: the color space of the image. If ``None``, a 1-channel image is ``GRAY``, a 3-channel
        image is ``RGB`` and any other channel count is ``UNKNOWN``. An explicit color space that does not
        match the channel count raises.
    channels_order: the layout of the capsule.

Raises:
    ValueError: if ``channels_order`` is neither ``CHANNELS_LAST`` nor ``CHANNELS_FIRST``.
    ValueCheckError: if an explicit ``color_space`` does not match the channel count (also a ``ValueError``).
    ShapeError: if the capsule has more than three dimensions. It is also a ``ValueError``.
    IndexError: if the capsule has fewer than three dimensions.

Example:
    >>> x = np.ones((3, 4, 5))  # (C, H, W)
    >>> img = Image.from_dlpack(x.__dlpack__())
    >>> img.channels, img.height, img.width
    (3, 4, 5)
    >>> hwc = Image.from_numpy(np.ones((4, 5, 3), dtype=np.uint8))  # (H, W, C), CHANNELS_LAST
    >>> back = Image.from_dlpack(hwc.to_dlpack(), hwc.pixel_format.color_space, hwc.channels_order)
    >>> back.channels, back.height, back.width
    (3, 4, 5)

r¦   r¥   rI   r§   )r   r¨   rƒ   r‹   r   r   rX   r%   r   r2   r   )	r«   r)   r6   ry   r8   rm   r   r+   r,   s	   &&&&     r   r   ÚImage.from_dlpack”  sÙ   € ðL ¤-×">Ñ">Ä×@[Ñ@[Ð!\Ô\ÜÐ`ÓaÐaÜ)¨$Ó/ˆàœ]×9Ñ9Ô9Ü"¨%¯+©+°a­.ÀÇÁÈAÅÔOˆJØ—{‘{ 1•~‰Hä"¨%¯+©+°a­.ÀÇÁÈAÅÔOˆJØ—{‘{ 1•~ˆHàÒÜ.¨xÓ8ˆKÜ"¨{×FXÑFXÓFZÐ]^ÕF^Ô_ˆô ¨
ÐVdÔeˆá�5¨Ó/Ð/r   c               ó   € V ^8„  d   QhRR/# )r   r   r¶   r   )r   s   "r   r   r.   Î  s   € ÷ $ñ $˜6ñ $r   c                ó,   € \        V P                  4      # )a0  Return a DLPack capsule from the image torch.Tensor, sharing its memory.

The capsule holds the data in the image's own :attr:`channels_order`, ``(C, H, W)`` or ``(H, W, C)``, and
carries no color space; read it back with
``Image.from_dlpack(capsule, img.pixel_format.color_space, img.channels_order)``.
)r	   r)   rC   s   &r   r	   ÚImage.to_dlpackÎ  s   € ô ˜Ÿ™Ó#Ð#r   c               ó    € V ^8„  d   QhRRRR/# )r   Ú	file_pathú
str | Pathr   r'   r   )r   s   "r   r   r.   Ø  s   € ÷ /ñ / *ð /°ñ /r   c                ó`  € \        V\        P                  RR7      p\        \        P
                  VP                  4       ^,          R7      p\        \        VP                  ^,          VP                  ^,          R7      VP                  ^ ,          \        P                  R7      pV ! W#V4      # )a  Construct an ``Image`` from a file.

The file is loaded with :func:`~kornia.io.load_image` as ``ImageLoadType.RGB8``: the image is
``(3, H, W)`` ``uint8``, ``RGB`` and ``CHANNELS_FIRST``, on the CPU.

Args:
    file_path: the path to the file to read the image from.

r¯   )Údesired_typerG   rI   r¥   r§   )r   r   ÚRGB8r   r   r"   r2   r   r   rX   r   r¨   )r«   r½   r)   r+   r,   s   &&   r   Ú	from_fileÚImage.from_file×  s   € ô (¨	Ä×@RÑ@RÐ[`Ôaˆä"¬z¯~©~È×IZÑIZÓI\Ð_`ÕI`ÔaˆäÜ ¨¯
©
°1­¸T¿Z¹ZÈ½]ÔKØ—Z‘Z •]Ü(×7Ñ7ô
ˆñ
 �4 vÓ.Ð.r   c               ó    € V ^8„  d   QhRRRR/# )r   r½   r¾   r   r-   r   )r   s   "r   r   r.   î  s   € ÷ %ñ %˜zð %¨dñ %r   c                ó  € V P                   P                  \        P                  8X  d   V P	                  4       P
                  MV P
                  pV P                  \        P                  8X  d   VP                  ^^ ^4      p\        W4       R# )aÿ  Write the image to a file.

The format follows the file extension; see :func:`kornia.io.write_image` for the supported formats. A ``BGR``
image is converted to RGB first, so the file holds the true colors.

Args:
    file_path: the path to the file to write the image to.

Example:
    >>> data = np.ones((4, 5, 3), dtype=np.uint8)  # HxWxC
    >>> img = Image.from_numpy(data)
    >>> import tempfile, os
    >>> with tempfile.TemporaryDirectory() as tmp:
    ...     img.write(os.path.join(tmp, "test.jpg"))

N)r+   r6   r   r‰   rš   r)   ry   r   rƒ   r…   r   )r;   r½   r)   s   && r   ÚwriteÚImage.writeî  sc   € ð" &*×%6Ñ%6×%BÑ%BÄjÇnÁnÔ%Tˆt�{‰{‹}×!Ò!ÐZ^×ZcÑZcˆØ×Ñ¤-×"=Ñ"=Ô=Ø—<‘<  1 aÓ(ˆDÜ�IÖ$r   c               ó    € V ^8„  d   QhRRRR/# )r   Ú	max_widthr   r   r-   r   )r   s   "r   r   r.     s   € ÷ 0ñ 0˜sð 0¨Tñ 0r   c                ó0  € V P                   P                  \        P                  8X  d   V P	                  4       P
                  MV P
                  pV P                  \        P                  8X  d   VP                  ^^ ^4      p\        \        W!4      4       R# )a§  Print the image torch.Tensor to the console.

Args:
    max_width: the widest image, in pixels, that is printed without resizing; see
        :func:`~kornia.image.image_to_string`.

A ``BGR`` image is converted to RGB first, so the terminal shows the true colors.

.. code-block:: python

    img = Image.from_file("panda.png")
    img.print()

.. image:: https://github.com/kornia/data/blob/main/print_image.png?raw=true

N)r+   r6   r   r‰   rš   r)   ry   r   rƒ   r…   Úprintr   )r;   rÉ   r)   s   && r   rË   ÚImage.print  sh   € ð" &*×%6Ñ%6×%BÑ%BÄjÇnÁnÔ%Tˆt�{‰{‹}×!Ò!ÐZ^×ZcÑZcˆØ×Ñ¤-×"=Ñ"=Ô=Ø—<‘<  1 aÓ(ˆDÜŒo˜dÓ.Ö/r   )r8   r:   r9   )NN)é   )%Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r>   rD   rL   rQ   Úpropertyr)   rX   r4   rG   r+   r,   r   rm   rq   ru   ry   r~   r’   rš   rŸ   Úclassmethodr   rƒ   rª   r³   r¨   r   r	   rÂ   rÆ   rË   Ú__static_attributes__r   r   r   r'   r'   6   s…  † ñ?õB&õPe÷6õ0Hð ôó ðð ôó ðð ôó ðð ô ó ð ð ô"ó ð"ð ôó ðð ô$ó ð$ð ô&ó ð&ð ô2ó ð2ð ô1ó ð1ð ô*ó ð*õ
,õ.õ@.õ4.ð6 ð -1Ø(5×(CÑ(Cö	2Aó ð2Aõh	ð ð -1Ø(5×(DÑ(Dö	70ó ð70õr$ð ô/ó ð/õ,%÷,0ó 0r   r'   )'Ú
__future__r   Úpathlibr   Útypingr   r   r   rK   Útorch.utils.dlpackr   r	   Úkornia.colorr†   Úkornia.core.checkr
   Úkornia.core.exceptionsr   Úkornia.image.baser   r   r   r   r   r   Úkornia.image.image_printr   Úkornia.io.ior   r   r   r¢   r¶   r!   r"   r‰   r5   r%   r'   r   r   r   Ú<module>rà      sw   ðõ$ #å ß 'Ñ 'ã ß 5ã Ý 0Ý 2÷÷ õ 5ß ?Ñ ?ð €
Ø	€ð 'ŸO™O¨Q°
·±ÀÀ:Ç>Á>ÐSTÐUÐ õU÷
b0ó b0r   