Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Import and Show the Image | Image Processing
Fundamentals of Image Manipulation with Python

book
Import and Show the Image

In order to read (import) an image in Python with the OpenCV library, you can use the cv2.imread() function. This function takes one parameter, which is the file path of the image you want to import. The function returns the image as a NumPy array, which can then be used for further processing.

Task

Swipe to start coding

  1. Import the cv2 library and the pyplot module of matplotlib with plt alias.
  2. Read the image "image1.jpg".
  3. Show the image as a plot.

Solution

import cv2
import matplotlib.pyplot as plt

# Read the image file
img = cv2.imread("image1.jpg")

# Show the image with matplotlib
plt.imshow(img);

Mark tasks as Completed
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt