An Edge is a boundary between two regions having different intensity level. When an image change from black to white or vice versa we get an edge. Edge detection is very useful in detecting discontinuity of an image. There are different types of edges in an image like Step Edges, Ramp Edges, Ridge Edges. In image processing, we follow following steps to find an Edge.
Smoothing: suppress as much noise as possible, without destroying the true
Enhancement: apply a filter to enhance the quality of the edges in the image
Detection: determine which edge pixels should be discarded as noise and
which should be retained (usually, thresholding provides the criterion used for
Localization: determine the exact location of an edge (sub-pixel resolution
might be required for some applications, that is, estimate the location of an edge to
better than the spacing between pixels). Edge thinning and linking are usually
required in this step.
Derivation technique may be helpful in finding edges of an image.
Points which lie on an edge can be detected by:
Detecting local maxima or minima of the first derivative
Detecting the zero-crossing of the second derivative
In open cv we may perform it by following coding technique:
import cv2 import numpy as np filename = 'road.jpg' img = cv2.imread(filename) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) gray = np.float32(gray) dst = cv2.cornerHarris(gray,2,3,0.04) #result is dilated for marking the corners, not important dst = cv2.dilate(dst,None) # Threshold for an optimal value, it may vary depending on the image. img[dst>0.01*dst.max()]=[0,0,255] cv2.imshow('dst',img) if cv2.waitKey(0) & 0xff == 27: cv2.destroyAllWindows()
For Details refer: