• Stars
    star
    180
  • Rank 213,097 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Load an image file into a numpy array with Exif orientation support. Prevents upside-down and sideways images!

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

What is Exif Orientation data?

Most images captured by cell phones and consumer cameras aren't stored on disk in the same orientation they appear on screen. Exif Orientation data tells the program which way the image needs to be rotated to display correctly. Not handling Exif Orientation is a common source of bugs in Computer Vision and Machine Learning applications.

You can learn more about images and Exif Orientation data in my article here.

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

More Repositories

1

face_recognition

The world's simplest facial recognition api for Python and the command line
Python
52,535
star
2

node-unfluff

Automatically extract body content (and other cool stuff) from an html document
HTML
2,151
star
3

amplify

A Jekyll html theme in the vague style of Medium.com built using Google AMP
CSS
1,872
star
4

show-facebook-computer-vision-tags

A very simple Chrome Extension that displays the automated image tags that Facebook has generated for your images
JavaScript
1,485
star
5

face_recognition_models

Trained models for the face_recognition python library
Makefile
346
star
6

all-podcasts-dataset

A free dataset of (almost) all publicly available podcasts.
127
star
7

medium_to_ghost

Instantly move all your Medium.com content (formatted posts + images) to an open source Ghost blog!
Python
121
star
8

node-pullquoter

Automatically pull interesting quotes out of an article.
CoffeeScript
115
star
9

image_segmentation_examples

Examples of Image Segmentation with Mask R-CNN from PyImageConf 2018
Python
44
star
10

spanish-to-english-translation

Example of building a working Spanish-to-English translation model with Marian NMT
Python
21
star
11

titanic_machine_learning_example

A simple example of how to solve Kaggle's "Titanic: Machine Learning from Disaster" challenge using Python and scikit-learn
Python
12
star
12

pyflight

A Python Wrapper around Google's QPX Express API that supports both asynchronous and synchronous operation.
Python
3
star
13

london_bus_simple_led_sign

a simple london bus arrival sign script to use on a raspberry pi to show a kid how that works
Python
2
star