The basic operations performed on the image are:
- Convert image to NumPy Array
- Convert/transform OpenCV read image to RGB from BRG channel
- Reading image as a gray image
- Resize Image
- Resize Image using Ratio
- Flip Images
- Save Image
import numpy as np
import matplotlib.pyplot as plt
import cv2
# Image Read
img = cv2.imread('signature.jpeg') # automatically converted to numpy array
type(img) # should be: numpy.ndarray, not NoneType
img.shape
# Both opencv and matplotlib read image channels differently
# matplotlib -> RGB = Red Green Blue
# opencv -> BGR = Blue Green Red
plt.imshow(img)
# Convert/tranform opencv read image to RGB from BRG channel
fixed_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(fixed_img)
# Reading image as a gray image
gray_img = cv2.imread('signature.jpeg', cv2.IMREAD_GRAYSCALE)
type(gray_img)
gray_img.shape
plt.imshow(gray_img, cmap='gray')
# Resize Image
resize_img = cv2.resize(fixed_img, (600, 250)) # width x height
plt.imshow(resize_img)
# Resize Image using Ratio
w_ratio=0.5 # 50% Width
h_ratio=0.5 # 50% height
ratio_img = cv2.resize(fixed_img, (0,0), fixed_img, w_ratio, h_ratio)
plt.imshow(ratio_img)
# Flip Images
flip_img = cv2.flip(fixed_img,1) # can be 0,1,-1
plt.imshow(flip_img)
#Save Image
cv2.imwrite('flip_signature.jpeg', fixed_img)

