Pillow 在jupyter中使用matplotlib来显示图片

举报
千江有水千江月 发表于 2020/12/28 16:31:44 2020/12/28
【摘要】 所属的课程名称及链接[AI基础课程--常用框架工具]环境信息* ModelArts  * Notebook - Multi-Engine 2.0 (python3)    * JupyterLab - Notebook - Conda-python3      * Pillow 5.0.0Pillow 在jupyter中使用matplotlib来显示图片%matplotlib inlinef...

所属的课程名称及链接

[AI基础课程--常用框架工具]


环境信息

  • * ModelArts
    •   * Notebook - Multi-Engine 2.0 (python3)
      •     * JupyterLab - Notebook - Conda-python3
        •       * Pillow 5.0.0


Pillow 在jupyter中使用matplotlib来显示图片

%matplotlib inline
from PIL import Image
import matplotlib.pyplot as plt

img = Image.open('image.png')

# img.show() 失效
# 建议初学者使用 plt.imshow ,它带有坐标轴,便于理解一些传入 坐标参数的函数
plt.imshow(img)
<matplotlib.image.AxesImage at 0x7f4632232dd8>

pil-jupyter-show-img.png


Pillow jupyter 直接显示图片

from PIL import Image
img = Image.open('image.png')
# 这样做就没有 matplotlib 的坐标轴了
# 其它的一些用 plt 显示图片报错的时候,也可以用这种方法直接显示
img

pil-jupyter-show-img-2.png


help

help(Image.open)

Help on function open in module PIL.Image:

open(fp, mode='r')
    Opens and identifies the given image file.
    
    This is a lazy operation; this function identifies the file, but
    the file remains open and the actual image data is not read from
    the file until you try to process the data (or call the
    :py:meth:`~PIL.Image.Image.load` method).  See
    :py:func:`~PIL.Image.new`.
    
    :param fp: A filename (string), pathlib.Path object or a file object.
       The file object must implement :py:meth:`~file.read`,
       :py:meth:`~file.seek`, and :py:meth:`~file.tell` methods,
       and be opened in binary mode.
    :param mode: The mode.  If given, this argument must be "r".
    :returns: An :py:class:`~PIL.Image.Image` object.
    :exception IOError: If the file cannot be found, or the image cannot be
       opened and identified.


备注

1. 感谢老师的教学与课件  
2. 欢迎各位同学一起来交流学习心得^_^  
3. 沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。  


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。