File size: 545 Bytes
d4e7f2f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import torch
import numpy as np
from PIL import Image
def read_hwc(path: str) -> torch.Tensor:
"""Read an image from a given path.
Args:
path (str): The given path.
"""
image = Image.open(path)
np_image = np.array(image.convert('RGB'))
return torch.from_numpy(np_image)
def write_hwc(image: torch.Tensor, path: str):
"""Write an image to a given path.
Args:
image (torch.Tensor): The image.
path (str): The given path.
"""
Image.fromarray(image.cpu().numpy()).save(path)
|