v Sharpen Images - Machine Learning

Sharpen 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)

Sharpen Image

# Create kernel
kernel = np.array([[0, -1, 0], 
                   [-1, 5,-1], 
                   [0, -1, 0]])

# Sharpen image
image_sharp = cv2.filter2D(image, -1, kernel)

View Image

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

png