Image Processing -Edge detection: Part 1

Shubham Pandey
4 min readJun 13, 2022

--

In an interview, I was being questioned about Image processing and there, I was asked questions on edges, at that time I was not much into the theoretical aspect of things but more of a ‘let’s implement and see’ kind of person. And needless to say, I failed terribly when they started going deep and deep into this simple concept itself. And after that failure, I realised, man! there is so much left before I can even consider myself a computer vision engineer. So if you hit an almost similar roadblock or got a guilty conscience that yeah I can use it but I don’t know what it is, join my journey.

So what is an edge? In our 3D world, Edges are the intersection of two (sur)faces or simply the lines that separate surfaces from one another. OKAY, but how can we identify them in a 2D image.

The blue line represents an edge

Here you can see 3 faces labelled as 1,2,3 and a blue line representing an edge. And if you have not guessed it, it’s an image of a 3D object :). Now to the question, how do we identify an edge in an image? It is actually pretty simple. The area where there is a sudden change in pixel intensity(see the area represented by little arrows on faces 2&3 in the image)defines the edge and the group of pixels that provide you with that information makes up edges, Wow!! that wasn’t so hard.

The bottom line is if we are out for edge-hunting we need to get pixels that separate two discontinuous regions represented in terms of pixel intensity.

And now that, we have fully established what an edge is, let’s go on to how to detect these edges.

But first, there is something you should know,

Linear filtering is the filtering method in which the value of the output pixel is a linear combination of the neighbouring input pixels. it can be done with convolution. For example, mean/average filters or Gaussian filtering.

Non-linear filtering cannot be done with convolution or Fourier multiplication. A sliding median filter is a simple example of a non-linear filter.

How does edge detection work? (A non-mathematical explanation)

Focus on two boxes the orange one and the black one, the black one is a little bit off from the edge whereas the orange one looks like it lies on the edge, now that’s a visual result but how does a computer identify an edge? It does that by using something called the kernel(or filter), which is a matrix when convolved with the image in a sliding window fashion gives a feature map. The values on the feature map will tell if a certain pixel is on an edge or not. For example, after applying the above filter shown in blue( a Prewitt filter — X direction), it provides us with the difference between right pixels(intensity) and left pixels(remember the definition?), so in the case where the difference is large the target pixel is said to lie on edge, like in our case we get 125(black) and 260(orange) clearly orange has a much higher value hence it lies on the edge.

Methods of Edge Detection

Here are some of the masks for edge detection that we will discuss in the upcoming tutorials. These are all linear filters(the ones that are used by convolving them with a given image, as explained in the quote section).

  • Prewitt Operator
  • Sobel Operator
  • Farid Operator
  • Scharr Operator.

Now to not make this blog too lengthy, we will start part 2 directly with the filters and explain them one by one, and possibly do some code too :)

But before ending let's see the result Prewitt kernel returns on the example we used.

Thank you for reading, see you in Part 2.

--

--

Shubham Pandey
Shubham Pandey

Written by Shubham Pandey

Machine Learning enthusiast, post blogs on Deep Learning techniques, tips and tricks.trying to make a name for myself in the community.

No responses yet