
上QQ阅读APP看书,第一时间看更新
Converting image data structures
The following code block shows how to convert from the PIL Image object into numpy ndarray (to be consumed by scikit-image):
im = Image.open('../images/flowers.png') # read image into an Image object with PIL
im = np.array(im) # create a numpy ndarray from the Image object
imshow(im) # use skimage imshow to display the image
plt.axis('off'), show()
The next figure shows the output of the previous code, which is an image of flowers:
The following code block shows how to convert from numpy ndarray into a PIL Image object. When run, the code shows the same output as the previous figure:
im = imread('../images/flowers.png') # read image into numpy ndarray with skimage
im = Image.fromarray(im) # create a PIL Image object from the numpy ndarray
im.show() # display the image with PIL Image.show() method