from PIL import Image from numpy import asarray img = Image.open('Sample.png') numpydata = asarray(img) print(type(numpydata)) print(numpydata.shape)
Here is what the above code is Doing:
1. We are importing the Image class from the PIL (pillow) module.
2. We are importing the asarray() function from the numpy module.
3. We are opening the image using the Image.open() function.
4. We are converting the image to a numpy array using the asarray() function.
5. We are printing the type of the numpy array.
6. We are printing the shape of the numpy array.