Skip to content
Advertisement

Canny edge detection not working on Gaussian blurred images

I am trying to detect edges on this lane image. First blurred the image using Gaussian filter and applied Canny edge detection but it gives only blank image without detecting edges.

input image enter image description here

I have done like this:

#imports
import matplotlib.pyplot as plt
import numpy as np
import cv2
import matplotlib.image as mpimg

image= mpimg.imread("Screenshot from Lane Detection Test Video 01.mp4.png")
image = image[:,:,:3]
image_g = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

image_blurred = cv2.GaussianBlur(image_g, (3, 3), 0)
threshold_low = 50
threshold_high = 100
image_blurred = image_blurred.astype(np.uint8)
image_canny = cv2.Canny(image_blurred, threshold_low, threshold_high)
plt.imshow(image_canny,cmap='gray')  

Advertisement

Answer

You should always examine your data. Simply running your script step by step and examining intermediate values shows what is going wrong: mpimg.imread reads the image as a floating-point array with values between 0 and 1. After blurring, you cast it to uint8, which sets almost all values to 0. Simply multiplying the image by 255 at some point before casting to uint8 solves your issue.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement