亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Industrial programming >> Python

Python 图像处理与 Pillow

Pillow Python Imaging Library 是图像处理的理想选择。通常,它用于存档和批处理应用程序。当然,您可以随意将其用于您能想到的任何其他事情。您可以使用该库:

目录

<导航>

安装图像处理包

要安装 Pillow,它是原始 Python Imaging Library 的一个分支和延续,请使用 pip install 命令:

pip3 install Pillow

处理图像

Pillow 提供了几个过滤器,这些过滤器在导入 ImageFilter 后可用 .例如,要模糊图像,请使用:

from PIL import Image, ImageFilter

im = Image.open("kittens.jpg")
blurred = im.filter(ImageFilter.BLUR)

其他过滤器包括 SHARPEN、SMOOTH 和 EDGE_ENHANCE。有关过滤器的完整列表,请查看 ImageFilter 上的参考文档。

将图像旋转 180 度:

rotated_image = im.rotate(180) 

最后,为了保存您辛勤工作的成果:

rotated_image.save("rotated.jpg")

显示图片

除了图像处理,这个库还可以用于在屏幕上显示图像。下面是一些示例代码,用于显示名为 kittens.jpg 的文件 :

from PIL import Image

im = Image.open("kittens.jpg")
im.show()
print(im.format, im.size, im.mode)
# JPEG (1920, 1357) RGB

在下面的动画 gif 中,我演示了如何直接从 IPython 使用 Pillow:

进一步阅读

图书馆有更多的东西可以提供。想要学习使用 Pillow 进行 Python 图像处理的一切,最好去官方教程学习!


Python

  1. 使用 Raspberry Pi 和 Python 构建机器人
  2. Python Print() 语句:如何通过示例打印
  3. Python String strip() 函数与示例
  4. 带有示例的 Python 字符串计数()
  5. Python String format() 举例说明
  6. Python String find() 方法及示例
  7. 带有示例的 Python Lambda 函数
  8. 带有示例的 Python round() 函数
  9. 带有示例的 Python map() 函数
  10. Python Timeit() 与示例
  11. 集合中的 Python 计数器示例
  12. Python 中的 type() 和 isinstance() 示例