Pillow is a python image library. It is by deafult installed by andconda. It is even required for simple image loading and saving in other Python scientific libraries such as Matplotlib.
from PIL import Image
img = Image.open('opera_house.jpg')
print(img.format)
print(img.mode)
print(img.size)
For this at first we need to import asarray function from numpy. The asarray() function is used to convert an given input to an array. Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.
Now we pass img object to the asarray() function and it returns an array.
#import library
from numpy import asarray
#convert image to numpy array which is loaded before
data = asarray(img)
We can see the type of this array using python python built in type() function and it returns the type of this array
type(data)
print(data.shape)
img2 = Image.fromarray(data)
img2
img2 = Image.fromarray(data)
img2
We can also do this by Matplotlib with pillow installed.
We can load image with imread() function.
At first we import image and pyplot from matplotlib
#Load libraries of matplotlib
from matplotlib import image,pyplot
#load image
data = image.imread('opera_house.jpg')
Now chekc the type of this data using the same thing we have done before.
type(data)
Now check the data details
print(data.dtype)
print(data.shape)
Now we show the image
pyplot.imshow(data)
pyplot.show()
For details Check This Code