Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Computer Vision Workshop

You're reading from   The Computer Vision Workshop Develop the skills you need to use computer vision algorithms in your own artificial intelligence projects

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781800201774
Length 568 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Nikhil Singh Nikhil Singh
Author Profile Icon Nikhil Singh
Nikhil Singh
Hafsa Asad Hafsa Asad
Author Profile Icon Hafsa Asad
Hafsa Asad
Vishwesh Ravi Shrimali Vishwesh Ravi Shrimali
Author Profile Icon Vishwesh Ravi Shrimali
Vishwesh Ravi Shrimali
Arrow right icon
View More author details
Toc

1. Basics of Image Processing

Activity 1.01: Mirror Effect with a Twist

Solution:

  1. Let's start by importing the necessary libraries:
    # Load modules
    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
  2. Next, let's specify the magic command for displaying images in a notebook:
    %matplotlib inline
  3. Now, we can load the image and display it using Matplotlib.

    Note

    Before proceeding, ensure that you can change the path to the images (highlighted) based on where the image is saved in your system.

    The code is as follows:

    # Load image
    img = cv2.imread("../data/lion.jpg")
    plt.imshow(img[:,:,::-1])
    plt.show()

    The output is as follows:

    Figure 1.42: Image that we are going to use in this activity

  4. Next, let's display the image's shape:
    # Get image shape
    img.shape

    The output is (407, 640, 3).

  5. Convert the image into HSV:
    # Convert image to HSV
    imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    plt.imshow(imgHSV[:,:,::-1])
    plt.show()

    The output is as follows...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime