Import Libraries


In [1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
import scipy.ndimage.filters as sci

Read Image


In [2]:
img0 = cv2.imread('face.jpg',)
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)

Remove Noise


In [3]:
img = cv2.GaussianBlur(gray,(3,3),0)

Convolute with proper kernels


In [4]:
laplacian = cv2.Laplacian(img,cv2.CV_64F)
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)  # x
sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)  # y

Plot Results


In [5]:
plt.figure(figsize=(20,18))
plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray'), plt.title('Original')
plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray'), plt.title('Laplacian')
plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray'), plt.title('Sobel X')
plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray'), plt.title('Sobel Y')

plt.show()