Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

2. Common Operations When Working with Images

Activity 2.01: Masking Using Binary Images

Solution:

  1. Create a new notebook – Activity2.01.ipynb. We will be writing our code in this notebook.
  2. Import the required libraries:
    # Import modules
    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib inline
  3. Read the image of the disk and convert it to grayscale.

    Note

    Before proceeding, be sure to change the path to the image (highlighted) based on where the image is saved in your system.

    The code for this is as follows:

    img = cv2.imread("../data/recording.jpg")
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  4. Display the grayscale image using Matplotlib:
    plt.imshow(img, cmap='gray')
    plt.show()

    The output is as follows. The X and Y axes refer to the width and height of the image, respectively:

    Figure 2.53: Disk image

  5. Threshold this image with a threshold of 150 and a maximum value of 255:
    # Set threshold and maximum value
    thresh = 150...
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 $19.99/month. Cancel anytime
Banner background image