Image Processing
Image Transformations
Translation
Rotation
Resizing
Flipping
Cropping
# Import the necessary packages
import numpy as np
import cv2
# Load the image and show it
image = cv2.imread(args["image"])
cv2.imshow("Original", image)
# NOTE: Translating (shifting) an image is given by a
# NumPy matrix in the form:
# [[1, 0, shiftX], [0, 1, shiftY]]
# You simply need to specify how many pixels you want
# to shift the image in the X and Y direction.
# Let's translate the image 25 pixels to the right and
# 50 pixels down
M = np.float32([[1, 0, 25], [0, 1, 50]])
shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
cv2.imshow("Shifted Down and Right", shifted)
# Now, let's shift the image 50 pixels to the left and
# 90 pixels up. We accomplish this using negative values
M = np.float32([[1, 0, -50], [0, 1, -90]])
shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
cv2.imshow("Shifted Up and Left", shifted)
Image Arithmetic
Bitwise Operations
Masking
Splitting and Merging Channels
Color Spaces