Title: Load Images
Slug: load_images
Summary: How to load images using OpenCV in Python.
Date: 2017-09-11 12:00
Category: Machine Learning
Tags: Preprocessing Images
Authors: Chris Albon
In [1]:
# Load library
import cv2
import numpy as np
from matplotlib import pyplot as plt
In [2]:
# Load image as grayscale
image = cv2.imread('images/plane.jpg', cv2.IMREAD_GRAYSCALE)
# Show image
plt.imshow(image, cmap='gray'), plt.axis("off")
plt.show()
In [3]:
# Load image in color
image_bgr = cv2.imread('images/plane.jpg', cv2.IMREAD_COLOR)
# Convert to RGB
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
# Show image
plt.imshow(image_rgb), plt.axis("off")
plt.show()
In [4]:
# Show image data
image
Out[4]:
In [5]:
# Show dimensions
image.shape
Out[5]: