v Cropping Images - Machine Learning

Cropping Images

Preliminaries

# Load image
import cv2
import numpy as np
from matplotlib import pyplot as plt

Load Image As Greyscale

# Load image as grayscale
image = cv2.imread('images/plane_256x256.jpg', cv2.IMREAD_GRAYSCALE)

Crop Image

# Select first half of the columns and all rows
image_cropped = image[:,:126]

View Image

# View image
plt.imshow(image_cropped, cmap='gray'), plt.axis("off")
plt.show()

png