In [1]:
import numpy as np
from PIL import Image
src_path = "data/src/lena.jpg"
img = Image.open(src_path).convert('RGB')
In [2]:
print(type(img))
In [3]:
print(img.size) # (width, height)
In [4]:
# PIL Image to ndarray
arr = np.array(img)
print(type(arr))
In [5]:
print(arr.shape) # (height, width, channel)
In [6]:
# ndarray to PIL Image
img2 = Image.fromarray(np.uint8(arr))
print(type(img2))