photosynthesis-team / piq

Measures and metrics for image2image tasks. PyTorch.
Apache License 2.0
1.4k stars 120 forks source link

Allow using *.png files (or) document how to open *.png files #372

Closed CrHasher closed 1 year ago

CrHasher commented 1 year ago

Support for png files (or) example on how to open one:

x = torch.tensor(imread(img_file_path)).permute(2, 0, 1)[None, ...] / 255.

The above does not work for PNG files.

CrHasher commented 1 year ago

Never mind this works:

def convert_to_rgb(img):
    # Check the number of channels and convert to RGB if not 3 channels
    if img.ndim == 2:  # grayscale
        img = color.gray2rgb(img)
    elif img.shape[2] == 4: # RGBA
        img = img[:, :, :3] # Drop the alpha channel
    return img

#...
x = torch.tensor(convert_to_rgb(imread(img_file_path))).permute(2, 0, 1)[None, ...] / 255.

But please let me know if I'm doing it wrong.