使用正确的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()

谢谢

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Hibernate:合并并删除,而不是从数据库中删除实体对象   java如何在WebFilter中有条件地从Mono返回?   java调用mysql c3p0函数   可执行jar Java jar文件加载错误:无法找到或加载主类。类导致的错误:java。lang.ClassNotFoundException:某些东西。班   java如何减少/更改爬网后的延迟?   从其他语言(如Java、PHP、Perl、Python等)调用C/C++代码的最佳方式是什么?   java如何模拟影响对象的void返回方法   当我试图在ubuntu上启动JavaScala时,它抛出了一个异常   java如何正确输出游戏   理解java和C++背景下的JavaScript原型   oracle如何将Java函数转换为postgresql函数   多线程为什么我的java服务器程序在超时后不退出?   java如何使listView中的按钮在单击时工作?   试图将这个嵌套的java forloop转换为python,但我不知道如何转换。有没有一种方法可以像这样为循环执行if语句?   java幂函数在计算器中的应用   如何在java中滚动浏览mysql数据库   在Spring Boot应用程序的JUnit测试中,java没有符合自动连线JPA存储库要求的bean   java如何使用扩展类的JPanel对象?