How to import (load) an image in python ? 您所在的位置:网站首页 myimagefromdesktopjpg How to import (load) an image in python ?

How to import (load) an image in python ?

2023-07-25 12:44| 来源: 网络整理| 查看: 265

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 matplotlib

To 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()

 Comment importer et tourner une image avec matplotlib ? Comment importer et tourner une image avec matplotlib ?

Import an image using Pillow

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.JpegImageFile

However 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 Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有