Skip to content

Commit 1106a25

Browse files
committed
Doc
1 parent af91362 commit 1106a25

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

torchvision/io/image.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ def decode_png(
7575
) -> torch.Tensor:
7676
"""
7777
Decodes a PNG image into a 3 dimensional RGB or grayscale Tensor.
78-
Optionally converts the image to the desired format.
79-
The values of the output tensor are uint8 in [0, 255].
78+
79+
The values of the output tensor are in uint8 in [0, 255] for most cases. If
80+
the image is a 16-bit png, then the output tensor is uint16 in [0, 65535]
81+
(supported from torchvision ``0.21``. Since uint16 support is limited in
82+
pytorch, we recommend calling
83+
:func:`torchvision.transforms.v2.functional.to_dtype()` with ``scale=True``
84+
after this function to convert the decoded image into a uint8 or float
85+
tensor.
8086
8187
Args:
8288
input (Tensor[1]): a one dimensional uint8 tensor containing
@@ -144,7 +150,7 @@ def decode_jpeg(
144150
) -> torch.Tensor:
145151
"""
146152
Decodes a JPEG image into a 3 dimensional RGB or grayscale Tensor.
147-
Optionally converts the image to the desired format.
153+
148154
The values of the output tensor are uint8 between 0 and 255.
149155
150156
Args:
@@ -248,8 +254,13 @@ def decode_image(
248254
Detect whether an image is a JPEG, PNG or GIF and performs the appropriate
249255
operation to decode the image into a 3 dimensional RGB or grayscale Tensor.
250256
251-
Optionally converts the image to the desired format.
252-
The values of the output tensor are uint8 in [0, 255].
257+
The values of the output tensor are in uint8 in [0, 255] for most cases. If
258+
the image is a 16-bit png, then the output tensor is uint16 in [0, 65535]
259+
(supported from torchvision ``0.21``. Since uint16 support is limited in
260+
pytorch, we recommend calling
261+
:func:`torchvision.transforms.v2.functional.to_dtype()` with ``scale=True``
262+
after this function to convert the decoded image into a uint8 or float
263+
tensor.
253264
254265
Args:
255266
input (Tensor): a one dimensional uint8 tensor containing the raw bytes of the
@@ -277,8 +288,14 @@ def read_image(
277288
) -> torch.Tensor:
278289
"""
279290
Reads a JPEG, PNG or GIF image into a 3 dimensional RGB or grayscale Tensor.
280-
Optionally converts the image to the desired format.
281-
The values of the output tensor are uint8 in [0, 255].
291+
292+
The values of the output tensor are in uint8 in [0, 255] for most cases. If
293+
the image is a 16-bit png, then the output tensor is uint16 in [0, 65535]
294+
(supported from torchvision ``0.21``. Since uint16 support is limited in
295+
pytorch, we recommend calling
296+
:func:`torchvision.transforms.v2.functional.to_dtype()` with ``scale=True``
297+
after this function to convert the decoded image into a uint8 or float
298+
tensor.
282299
283300
Args:
284301
path (str or ``pathlib.Path``): path of the JPEG, PNG or GIF image.

0 commit comments

Comments
 (0)