xxxxxxxxxx
# checks this https://stackoverflow.com/questions/14759637/python-pil-bytes-to-image
xxxxxxxxxx
import io
from PIL import Image
imageFileObj = open(imageFilename, "rb")
imageBinaryBytes = imageFileObj.read()
imageStream = io.BytesIO(imageBinaryBytes)
imageFile = Image.open(imageStream)
print("imageFile.size=%s" % imageFile.size)
xxxxxxxxxx
from PIL import Image
import numpy as np
# Load the image using PIL
image = Image.open("image_file.jpg") # Replace "image_file.jpg" with the actual image file path
# Convert the PIL image to a NumPy array
image_array = np.asarray(image)
# Print the shape and type of the image array
print(image_array.shape)
print(image_array.dtype)