How to convert PIL image to NumPy array

You can convert the PIL image to a NumPy array with the following code. If you want to learn Python, I highly recommend reading This Book.

How to convert pil image to NumPy array
How to convert PIL image to NumPy array
# Import the required module
from PIL import Image
import numpy as np

# Read the Image
image = Image.open("man.jpg")

# Print the type of Image
print(type(image))

# Convert PIL to NumPy array
b = np.asarray(image)

# Display the type of b
print(type(b))

Output:

<class 'PIL.JpegImagePlugin.JpegImageFile'>
<class 'numpy.ndarray'>

Free Learning Resources

Leave a Comment

Your email address will not be published.