Skip to content

Instantly share code, notes, and snippets.

@SametSahin10
Last active January 7, 2024 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SametSahin10/1f48de74fca74d8e0c8425f843fee25f to your computer and use it in GitHub Desktop.
Save SametSahin10/1f48de74fca74d8e0c8425f843fee25f to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
# Load the image
image = cv2.imread('/Users/sametsahin/Downloads/scuba_diver.jpeg')
# Define all kernels
kernels = {
'Sobel Vertical': np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]),
'Sobel Horizontal': np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]]),
'Prewitt Vertical': np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]),
'Prewitt Horizontal': np.array([[-1, -1, -1], [0, 0, 0], [1, 1, 1]]),
'Sharpening': np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]),
'Box Blur': np.array([[1/9, 1/9, 1/9], [1/9, 1/9, 1/9], [1/9, 1/9, 1/9]]),
'Gaussian Blur': np.array([[1, 2, 1], [2, 4, 2], [1, 2, 1]]),
'Emboss': np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]),
'Laplacian Edge Enhancement': np.array([[0, 1, 0], [1, -4, 1], [0, 1, 0]])
}
# Apply each kernel and display the results
for name, kernel in kernels.items():
filtered_image = cv2.filter2D(image, -1, kernel)
cv2.imshow(name, filtered_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment