GithubHelp home page GithubHelp logo

00mjk / image_to_numpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ageitgey/image_to_numpy

0.0 0.0 0.0 39.96 MB

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

License: MIT License

Python 100.00%

image_to_numpy's Introduction

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

image_to_numpy's People

Contributors

ageitgey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.