Skip to main content

Load an image into a numpy array with proper Exif orientation handling

Project description

image_to_numpy

Load an image file into a numpy array - while automatically rotating the image based on Exif orientation. Prevents upside-down and sideways images!

import image_to_numpy

img = image_to_numpy.load_image_file("my_file.jpg")

The image is automatically rotated into the correct orientation if the image contains Exif orientation metadata. Otherwise, it is loaded normally.

From there, you can pass the numpy array to any Python library that works with images in numpy array format, like face_recognition, Keras, etc.

Installation

You can install from PyPI:

pip install image_to_numpy

Usage

import image_to_numpy

img = image_to_numpy.load_image_file("my_file.jpg")

Your image is loaded - with the correct orientation!

By default, the image array is returned as a numpy array with 3-channels of 8-bit RGB data.

You can control the output format by passing in an optional mode parameter:

import image_to_numpy

img = 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)

If you have matplotlib installed, here's a quick way to show your image on the screen:

import matplotlib.pyplot as plt
import image_to_numpy

img = image_to_numpy.load_image_file("my_file.jpg")

plt.imshow(img)
plt.show()

Thanks

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image_to_numpy-1.0.0.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file image_to_numpy-1.0.0.tar.gz.

File metadata

  • Download URL: image_to_numpy-1.0.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.25.0 CPython/3.7.4

File hashes

Hashes for image_to_numpy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1fd1da99b3b451d8bcf2aae21d184be9ef5745facf099fd23fcecf224675c791
MD5 3ef15bedaa10782c1d5c1b07fb512f20
BLAKE2b-256 b9765f1068fe491b011e9625f1da73f2d5c00e9d810dce39253ba6bcf886ac79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page