How to import (load) an image in python ? | 您所在的位置:网站首页 › myimagefromdesktopjpg › How to import (load) an image in python ? |
Examples of how to import (load) an image in python: Table of contents Import an image using matplotlib Import an image using Pillow References Import an image using matplotlibTo import an image in python, one solution is to use matplotlib: from matplotlib import image img = image.imread("eiffel-tower.jpeg")Note: print( type(img) ) print( img.shape )returns: and (1280, 850, 3)3 corresponds to RGB. It is then possible to plot the image using imshow from matplotlib plt.imshow(img) plt.show()![]() Another solution is to use Pillow from PIL import Image img= Image.open("eiffel-tower.jpeg")Note that here type(img)is not a numpy array: PIL.JpegImagePlugin.JpegImageFileHowever it is always possible to plot the image using imshow plt.imshow(img) plt.show()to convert img to a numpy array import numpy as np img = np.asarray(img) References Image tutorial Image Module Importing Image Data into NumPy Arrays![]() This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. |
CopyRight 2018-2019 实验室设备网 版权所有 |