PPM Format¶

read_ppm(
file_path: str,
) Tuple[Tensor, Literal[8, 9, 10, 11, 12, 13, 14, 15, 16]][source]¶

Read a PPM file, and return a torch tensor [1, 3, H, W] containing the data. The returned tensor is in [0., 1.] so its bitdepth is also returned.

Attention

We don’t filter out comments inside PPM files…

Parameters:

file_path (str) – Path of the ppm file to read.

Returns:

Image data [1, 3, H, W] in [0., 1.] and its bitdepth.

Return type:

Tuple[Tensor, Literal[8, 9, 10, 11, 12, 13, 14, 15, 16]]

write_ppm(
data: Tensor,
bitdepth: Literal[8, 9, 10, 11, 12, 13, 14, 15, 16],
file_path: str,
norm: bool = True,
) None[source]¶

Save an image x into a PPM file.

Parameters:
  • data (Tensor) – Image to be saved

  • bitdepth (Literal[8, 9, 10, 11, 12, 13, 14, 15, 16]) – Bitdepth, should be in [8, 9, 10, 11, 12, 13, 14, 15, 16].

  • file_path (str) – Where to save the PPM files

  • bitdepth – Bitdepth of the file. Defaults to 8.

  • norm (bool) – True to multiply the data by 2 ** bitdepth - 1. Defaults to True.

Return type:

None