Created
March 26, 2020 06:40
-
-
Save THEFASHIONGEEK/a33ac1714df235a6bb3c1d8226e615c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/a.jpg", 0) | |
dx = cv2.Sobel(img,cv2.CV_8UC1,1,0,ksize=5) # first order derivative around x | |
dy = cv2.Sobel(img,cv2.CV_8UC1,0,1,ksize=5) # first order derivative around y | |
dx2 = cv2.Sobel(img,cv2.CV_8UC1,2,0,ksize=5) # second order derivative around x | |
dy2 = cv2.Sobel(img,cv2.CV_8UC1,0,2,ksize=5) # second order derivative around y | |
dxy = cv2.Sobel(img,cv2.CV_8UC1,1,1,ksize=5) # first order derivative around x then y | |
f = plt.figure(figsize=(15,25)) | |
f.add_subplot(3, 2, 1).set_title('Original Image'); | |
plt.imshow(img, cmap="gray") | |
f.add_subplot(3, 2, 2).set_title('1st filter in X direction Image'); | |
plt.imshow(dx, cmap="gray"); | |
f.add_subplot(3, 2, 3).set_title('1st filter in Y direction Image'); | |
plt.imshow(dy, cmap="gray"); | |
f.add_subplot(3, 2, 4).set_title('2nd filter in X direction Image'); | |
plt.imshow(dx2, cmap="gray"); | |
f.add_subplot(3, 2, 5).set_title('2nd filter in Y direction Image'); | |
plt.imshow(dy2, cmap="gray"); | |
f.add_subplot(3, 2, 6).set_title('dxy'); | |
plt.imshow(dxy, cmap="gray"); | |
plt.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment