Reputation: 51
load_image function doesn't accept ndarray Type. The function only accept IMAGE type.
Is it possible to convert ndarray type into IMAGE type or _ImageCrop type into IMAGE type?
Upvotes: 0
Views: 200
Reputation: 862
import numpy as np
from PIL import Image
# monochrome:
X1 = np.random.randint(0, 255, size=(256,256), dtype=np.uint8)
image1 = Image.fromarray(X1, "L")
image1.show()
# color:
X2 = np.random.randint(0, 255, size=(256,256,3), dtype=np.uint8)
image2 = Image.fromarray(X2, "RGB")
image2.show()
Check out different modes:
https://pillow.readthedocs.io/en/5.2.x/handbook/concepts.html#concept-modes
Upvotes: 0
Reputation: 625
As per my understanding of the problem, you want to convert numpy array into image format (PIL). This can be done by following code:
import numpy
import PIL
#Convert nparray to PIL image
img = PIL.Image.fromarray(arr) #arr is numpy array
Upvotes: 1