使用正确的Exif方向处理将图像加载到numpy数组中
image-to-nump的Python项目详细描述
图片:趵to逖numpy
将图像文件加载到numpy数组中-同时根据 Exif方向。防止倒立和横向图像!在
import image_to_numpy
img = image_to_numpy.load_image_file("my_file.jpg")
如果图像包含Exif方向元数据,则图像将自动旋转到正确的方向。 否则,正常加载。在
从那里,您可以将numpy数组传递给任何处理图像的Python库 以numpy数组格式,如人脸识别、Keras等
安装
您可以从PyPI安装:
^{pr2}$使用
importimage_to_numpyimg=image_to_numpy.load_image_file("my_file.jpg")
您的图像已加载-方向正确!在
默认情况下,图像数组作为numpy数组返回 具有3个通道的8位RGB数据。在
您可以通过传入可选的mode
参数来控制输出格式:
importimage_to_numpyimg=image_to_numpy.load_image_file("my_file.jpg",mode="RGB")# Supported modes:# 1 (1-bit pixels, black and white, stored with one pixel per byte)# L (8-bit pixels, black and white)# RGB (3x8-bit pixels, true color)# RGBA (4x8-bit pixels, true color with transparency mask)# CMYK (4x8-bit pixels, color separation)# YCbCr (3x8-bit pixels, color video format)# I (32-bit signed integer pixels)# F (32-bit floating point pixels)
如果您安装了matplotlib,这里有一种快速显示图像的方法 在屏幕上:
importmatplotlib.pyplotaspltimportimage_to_numpyimg=image_to_numpy.load_image_file("my_file.jpg")plt.imshow(img)plt.show()
谢谢
- Dave Perrett/@daveperrett创建的单元测试中使用的EXIF测试映像 在
- 项目
标签: