【Python工具包/库推荐系列】- Python 图片处理包
如果您的Python应用程序以任何方式与图像进行交互,则Python映像库(也称为PIL或Pillow)是Python必需的。它使编写以各种格式打开,修改和保存图像的代码变得容易。[code]from PIL import Image#Open image using Image module
im = Image.open("images/cuba.jpg")
#Show actual Image
im.show()
#Show rotated Image
im = im.rotate(45)
im.show()
[/code]如果您要对图像进行更高级的处理(例如图像识别,在这种情况下,OpenCV将是一个不错的选择),Pillow不会自行裁切的。但是对于基本的图像导入,处理和导出,Pillow是您的首选解决方案。[code]
import cv2
import numpy as np
import matplotlib.pyplot as plt
image = cv2.imread("C://gfg//tomatoes.jpg", 1)
# Loading the image
half = cv2.resize(image, (0, 0), fx = 0.1, fy = 0.1)
bigger = cv2.resize(image, (1050, 1610))
stretch_near = cv2.resize(image, (780, 540),
interpolation = cv2.INTER_NEAREST)
Titles =["Original", "Half", "Bigger", "Interpolation Nearest"]
images =[image, half, bigger, stretch_near]
count = 4
for i in range(count):
plt.subplot(2, 2, i + 1)
plt.title(Titles[i])
plt.imshow(images[i])
plt.show()
[/code]
页:
[1]