Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Created February 27, 2017 14:20
Show Gist options
  • Select an option

  • Save hackintoshrao/0e8da3c3119713621b294c1e6a34640b to your computer and use it in GitHub Desktop.

Select an option

Save hackintoshrao/0e8da3c3119713621b294c1e6a34640b to your computer and use it in GitHub Desktop.
Canny edge detection
# Do all the relevant imports
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import cv2
# Read in the image and convert to grayscale
# Note: in the previous example we were reading a .jpg
# Here we read a .png and convert to 0,255 bytescale
image = mpimg.imread('exit-ramp.jpg')
gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)
# Define a kernel size for Gaussian smoothing / blurring
kernel_size = 5 # Must be an odd number (3, 5, 7...)
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)
# Define our parameters for Canny and run it
low_threshold = 55
high_threshold = 110
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)
# Display the image
plt.imshow(edges, cmap='Greys_r')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment