1. Basics of Image Processing
Activity 1.01: Mirror Effect with a Twist
Solution:
- Let's start by importing the necessary libraries:
# Load modules import cv2 import numpy as np import matplotlib.pyplot as plt
- Next, let's specify the magic command for displaying images in a notebook:
%matplotlib inline
- 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:
- Next, let's display the image's shape:
# Get image shape img.shape
The output is
(407, 640, 3)
. - 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...