Categories
Python Answers

How to convert a PIL Image into a numpy array with Python?

Spread the love

Sometimes, we want to convert a PIL Image into a numpy array with Python.

In this article, we’ll look at how to convert a PIL Image into a numpy array with Python.

How to convert a PIL Image into a numpy array with Python?

To convert a PIL Image into a numpy array with Python, we call numpy.array with the PIL image.

For instance, we write

pix = numpy.array(pic)

to call numpy.array with the pic PIL image object to return an array with the pixel data of pic.

Conclusion

To convert a PIL Image into a numpy array with Python, we call numpy.array with the PIL image.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *