Formally, an edge can be thought of as an area with rapid change in intensity in an image.
For continuous domains, we have the gradient operator
It gives the direction of change (a sort of 2D slope vector). This would be good for detecting edges, as by graphing out a gradient, we can identify the areas where there are sudden spikes, thus representing an edge.
However, images are not continuous functions, and therefore we will have to use an approximation of the gradient operator by taking differences.
For calculating, the x-component, we will need two adjacent pixels with the same ordinate.
For calculating, the y-component, we will need two adjacent pixels with the same abscissa.
So, we need 4 adjacent pixels, for computing the discrete gradient.
In simpler words, find the difference along the x direction and take their mean for partial derivated wrt x. Same for y, but find differences alon y direction.
The good thing with this discrete gradient computation, is that it can be made into a filter which can be convolved with the image. Now, we dont have to always choose pixels that are exactly adjacent. And depending on how we choose to calculate the discrete gradient, we have these methods of edge detection as discussed here.
The Roberts operator, computes the gradient in diagonal directions instead of x,y axes like we discussed above.
Now, since it looks at immediately adjacent pixels, it has good localization, but is also not resilient to noise.
The Prewitt operator computes the gradient for a 3x3 block of pixels, while "skipping" a line in between. It calculates gradient in x and y direction.
One shortcoming of the Prewitt operator, was that it gives equal weight to the pixels further away from the center. Sobel improves on Prewitt, by giving more weight to pixels closer to the center.
The Laplacian operator is a second order gradient. It is given by
For discrete signals, we calculate the difference of differences, that is the difference of gradients. So the smallest we can go is 3x3.
The standard laplacian filter is
Since the laplacian is essentially detecting zero crossing in the gradient (which is where the edges are), we will subtract 128 from (an 8bit) the image, to map
With the laplacian however, we cannot figure out the orientation and magnitude of the edge. Because we lose that information when we take the dervative a second time.
So far, we understand that