I'm trying to save and load a grayscale image in PIL:
import numpy as np
from PIL import Image, ImageOps
o = np.random.rand(100,100)*255
o = o.astype('uint8')
im = Image.fromarray((o))
im.save('test.webp', lossless=True)
im = Image.open(r"test.webp")
a = np.asarray(im)
a.shape
a.shape
outputs (100, 100, 3)
, apparently it is saved as a RGB image. This doesn't happen if I save the image as PNG, it loads as (100,100,1)
. What to do?