python作为机器学习和图像处理的利器,收到越来越多的推崇,特别是在图像处理领域,越来越多的研究和开发开始转向使用python语言,下面就介绍python图像处理中最基本的操作,即图像的读取显示与保存。 原文地址:https://blog.csdn.net/guduruyu/article/details/70738654
原文地址1、使用PIL模块
代码如下:
- from PIL import Image
- import numpy as np
- def test_pil():
- #读取图像
- im = Image.open(”lena.jpg”)
- #显示图像
- im.show()
- #转换成灰度图像
- im_gray = im.convert(”L”)
- im_gray.show()
- #保存图像
- im_gray.save(”image_gray.jpg”)
- return
显示结果如下:
2、使用scipy和matplotlib模块
代码如下:
- import numpy as np
- from scipy import misc
- import matplotlib.pyplot as plt
- def 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()
- return
显示结果如下: