Skip to content

Instantly share code, notes, and snippets.

@wermarter
Created January 25, 2017 12:06
Show Gist options
  • Save wermarter/e0eda04967ba16b369a948ddd8a38b2e to your computer and use it in GitHub Desktop.
Save wermarter/e0eda04967ba16b369a948ddd8a38b2e to your computer and use it in GitHub Desktop.
Sobel, Laplacian, Gaussian Blur, Canny Edge
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('me.png', 0)
img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
# img = cv2.GaussianBlur(img, (5, 5), 0)
img = cv2.Laplacian(img, cv2.CV_64F)
img = np.uint8(np.absolute(img))
canny = cv2.Canny(img, 200, 200)# Dissemination,
sobelX = cv2.Sobel(img, cv2.CV_64F, 1, 0)
sobelY = cv2.Sobel(img, cv2.CV_64F, 0, 1)
sobelX = np.uint8(np.absolute(sobelX))
sobelY = np.uint8(np.absolute(sobelY))
sobel = cv2.bitwise_or(sobelX, sobelY)
#sobel = cv2.GaussianBlur(sobel, (5, 5), 0)
#Never blur after edge detection because of counter effect, smoothing edges
hist = cv2.calcHist([img], [0], None, [256], [0, 256])
plt.figure()
plt.xlabel('Color space')
plt.ylabel('Number of pixel')
plt.xlim([0, 256])
plt.title('Yeah')
plt.plot(hist)
cv2.imshow('Orig', img)
# cv2.imshow('SobelX', sobelX)
# cv2.imshow('SobelY', sobelY)
cv2.imshow('SobelOR', sobel)
cv2.imshow('Canny', canny)
#plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment