Edge Detection Prof. B.A.Khivsara
What is Edge Detection? Identifying points/Edges in a digital image at which the image brightness changes sharply or has discontinuities. - Edges are significant local changes of intensity in an image. - Edges typically occur on the boundary between two different regions in an image.
Goal of edge detection Edge detection is extensively used in image segmentation when we want to divide the image into areas corresponding to different objects. If we need to extract different object from an image, we need Edge Detection. Using Edge Detection, we can- recognition, Image comparizon, Unaccepted object can be remove.
Variation of Intensity / Gray Level TYPES OF EDGES Variation of Intensity / Gray Level Step Edge Ramp Edge Line Edge Roof Edge
Process of Edge Detection There are three steps to perform edge detection: Noise reduction Edge enhancement Detection – Identify edges
Process of Edge Detection - Noise reduction where we try to suppress as much noise as possible, without smoothing away the meaningful edges. Original Image After Nois Reduction
Process of Edge Detection - Edge enhancement where we apply some kind of filter that responds strongly at edges and weakly elsewhere.
METHODS OF EDGE DETECTION First Order Derivative / Gradient Methods Roberts Operator Sobel Operator Prewitt Operator Second Order Derivative Laplacian Laplacian of Gaussian Optimal Edge Detection Canny Edge Detection
First Order Derivative At the point of greatest slope, the first derivative has maximum value E.g. For a Continuous 1-dimensional function f(t)
Gradient For a continuous two dimensional function Gradient is defined as
Gradient Methods – Roberts Operator Convolution Mask Gx = Gy= 1 -1 -1 1
Roberts Operator - Example The output image has been scaled by a factor of 5 Spurious dots indicate that the operator is susceptible to noise
Gradient Methods – Sobel Operator The 3X3 convolution mask smoothes the image by some amount , hence it is less susceptible to noise. But it produces thicker edges. So edge localization is poor Convolution Mask 1 2 -1 -2 -1 1 -2 2 Gx= Gy=
Sobel Operator - Example Compare the output of the Sobel Operator with Roberts The spurious edges are still present but they are relatively less intense Roberts operator has missed a few edges Sobel operator detects thicker edges Outputs of Sobel (top) and Roberts operator
Second Order Derivative Methods Zero crossing of the second derivative of a function indicates the presence of a maxima
Second Order Derivative Methods - Laplacian Defined as Mask Very susceptible to noise, filtering required, use Laplacian of Gaussian 1 -4
Second Order Derivative Methods - Laplacian of Gaussian Steps Smooth the image using Gaussian filter Enhance the edges using Laplacian operator Zero crossings denote the edge location Use linear interpolation to determine the sub-pixel location of the edge
Program #Libraries to be installed # sudo apt-get install python-opencv # sudo apt-get install python-matplotlib import cv2 from matplotlib import pyplot as plt img0 = cv2.imread('images.jpeg',)# loading image gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)# converting to gray scale img = cv2.GaussianBlur(gray,(3,3),0) # remove noise cv2.GaussianBlur(image,(Kernal_Hieght,Kernal_Width),SigmaX)
Program # convolute with proper kernels laplacian = cv2.Laplacian(img,cv2.CV_64F) sobelx = cv2.Sobel(img,cv2.CV_64F,1,0) # x sobely = cv2.Sobel(img,cv2.CV_64F,0,1) # y plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') plt.title('Original'), plt.xticks([]), plt.yticks([]) plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) plt.show()