Part 3-Canny function for Edge Detection

Kumar Brar
Analytics Vidhya
Published in
3 min readJan 18, 2020
Canny Image(obtained where Gradient value is above threshold limit)

In the previous article, we worked on getting a Gaussian blurred image( by reducing noise in the image) from our grayscale image.

Now, in this article, we are going to make use of the Canny Edge Detection. This method focuses only on detecting the edges where there is a significant gradient difference between the adjacent pixels. This is very important in Computer Vision techniques. The edges in the image must be detected to the best possible level, so that effective decisions and research should be made from there on.

In our road example, we want that the system or our self-driving car should be able to read the image of the road on real-time basis and make an intelligent decision about the lane lines. Then, it can detect easily the region and hence the specific area-of-interest.

Before using the Canny Edge Detection algorithm, let’s check what it is all about :

The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. It was developed by John F. Canny in 1986. Canny also produced a computational theory of edge detection explaining why the technique works. (Wikipedia)

Now, we know that any image can be represented as a matrix of pixels. As we know, that the grayscale image has only 1 channel and hence pixel values ranging from 0–255.

Now, we can represent this image as well using coordinates i.e. x and y values. X-axis is on the horizontal side taking columns into account, whereas Y-axis is on the vertical side used to take corresponding rows into account. Now, the product of rows and columns gives us the details of all pixels with their values. So, an image can also be represented as a mathematical function i.e.

f (x,y) : A function of pixel intensities, in all directions, x and y

Here, our Canny Edge detector will perform derivative on the image function, thus measuring the adjacent changes in intensities in all directions, x and y :

derivative(f(x,y))

So, as shown in the picture below, no change has a derivate of zero and a large change is indicated by a large derivative.

Left(No change with derivative =0 & Right(large change with large derivative

Canny function looks like this :

        cv2.Canny(image, low_threshold, high_threshold)

Below is the image showing a white line which is nothing but the edge as this line is the one which is acting as a division for black and white colors or technically, we can say that at these points there is a steep change in the intensity of adjacent pixels.

White line in-between on right represents the edge line as it is the division point of the image on the left

The documentation on Canny function recommends a ratio of 1:2 or 1:3 between low_threshold and high_threshold.

So, in our example, we have taken a ratio of 1:3 i.e.

          canny = cv2.Canny(blur, 50, 150)

Social Applications of Edge Detection

  1. License plate detection: Today, cars are everywhere. Intelligent traffic control will no doubt become the future trend. License plate detection technology is widely used in tollgates as well as parking lots in public places, companies, and residential areas. So improving this technology is of great practical value.
  2. Detecting hidden information in medical images: It is of utmost importance while analyzing medical images that we not only can detect the edges of an object; we can also detect some hidden information of the test object. It is impossible for these details to be detected via traditional methods because there is very little difference between the color of these details and the color of their surrounding regions. So, a variety of other edge detection methods have been developed like DPC, MDPC, QDPA and QDPC.

So, with this I am concluding the article. In the next article, we will move further with this project. Let me know, how you see this branch of Computer Vision and Self-Driving Cars.

Bibliography

--

--

Kumar Brar
Analytics Vidhya

I am a lifelong learner with an ongoing curiosity to learn new things and share them with others. This helps in brainstorming and implementing new ideas.