Skip to content

Instantly share code, notes, and snippets.

@dazcona
Created August 23, 2019 15:59
Show Gist options
  • Save dazcona/180e8c6dd3a0e9e899bf9eedfaf8ae87 to your computer and use it in GitHub Desktop.
Save dazcona/180e8c6dd3a0e9e899bf9eedfaf8ae87 to your computer and use it in GitHub Desktop.
Display matplotlib RGB images
# Display matplotlib RGB images
# https://www.pyimagesearch.com/2014/11/03/display-matplotlib-rgb-image/
# matplotlib: pyplot and mpimg to load and display our images
# plt.axis("off"): to remove the axes of the figure
# OpenCV: images are stored in BGR order rather than RGB!
# Matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image = mpimg.imread("chelsea-the-cat.png")
plt.axis("off")
plt.imshow(image)
plt.show()
# OpenCV
import cv2
image = cv2.imread("chelsea-the-cat.png")
plt.axis("off")
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment