首页 > 编程 > Python > 正文

Python图像处理之图像的读取、显示与保存操作【测试可用】

2019-11-25 13:32:17
字体:
来源:转载
供稿:网友

本文实例讲述了Python图像处理之图像的读取、显示与保存操作。分享给大家供大家参考,具体如下:

python作为机器学习和图像处理的利器,收到越来越多的推崇,特别是在图像处理领域,越来越多的研究和开发开始转向使用python语言,下面就介绍python图像处理中最基本的操作,即图像的读取显示与保存。

1、使用PIL模块

代码如下:

# -*- coding:utf-8 -*-from PIL import Imageimport numpy as npdef test_pil():  #读取图像  im = Image.open("lena.jpg")  #显示图像  im.show()  #转换成灰度图像  im_gray = im.convert("L")  im_gray.show()  #保存图像  im_gray.save("image_gray.jpg")  returntest_pil()

显示结果如下:

2、使用scipy和matplotlib模块

代码如下:

# -*- coding:utf-8 -*-import numpy as npfrom scipy import miscimport matplotlib.pyplot as pltdef test_misc():  #读取图像  im = misc.imread("lena.jpg")  #显示图像  plt.figure(0)  plt.imshow(im)  #旋转图像  im_rotate = misc.imrotate(im, 90)  plt.figure(1)  plt.imshow(im_rotate)  #保存图像  misc.imsave("lena_rotate.jpg", im_rotate)  plt.show()  returntest_misc()

显示结果如下:

更多关于Python相关内容可查看本站专题:《Python数学运算技巧总结》、《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程

希望本文所述对大家Python程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表