Thirdyearengineering.weebly.com



ASSIGNMENT NO.B1PROBLEM STATEMENT:Write a Python program to apply the edge detection algorithm on image and to find the edges use BBB / ARM Cortex A5/A9/M4 Mobile Boards. Use Sobel and Laplacian variant for edge detection.OBJECTIVE:1. To learn concepts of image processing.2. To learn the various edge detection algorithms.3. To learn programming in embedded hardware using BBB/ARM Cortex. PRIREQUISITES:Software: Python, Remote Desktop Client, Opencv.Hardware: BBB / ARM Cortex A5/A9/M4 Mobile BoardsTHEORY:Edge DetectionEdge detection is one of the fundamental operations when we perform image processing. It helps us reduce the amount of data (pixels) to process and maintains the structural aspect of the image. We're going to look into two commonly used edge detection schemes - the gradient (Sobel - first order derivatives) based edge detector and the Laplacian (2nd order derivative, so it is extremely sensitive to noise) based edge detector. Both of them work with convolutions and achieve the same end goal - Edge Detection.Sobel Edge DetectionSobel edge detector is a gradient based method based on the first order derivatives. It calculates the first derivatives of the image separately for the X and Y axes.The operator uses two 3X3 kernels which are convolved with the original image to calculate approximations of the derivatives - one for horizontal changes, and one for vertical. The picture below shows Sobel Kernels in x-dir and y-dir: Laplacian Edge Detection SobelUnlike the Sobel edge detector, the Laplacian edge detector uses only one kernel. It calculates second order derivatives in a single pass. A kernel used in this Laplacian detection looks like this:If we want to consider the diagonals, we can use the kernel below:Algorithm for Edge DetectionStep 1:- loading image.Step 2:- converting to gray scale.Step3:- remove noise.Step4:- convolute with proper kernels.Step5:- Display image. Algorithm for Edge Detection using Sobel operatorStep 1: Accept the input imageStep 2: Apply maskGx,Gy to the input imageStep 3: Apply Sobel edge detection algorithm and the gradientStep 4: Masks manipulation of Gx,Gy separately on the input imageStep 5: Results combined to find the absolute magnitude of the gradientG=GX2+GY2Step 6: the absolute magnitude is the output edges.Conclusion: - In this way we perform edge detection algorithm on image and to find the edges using BBB Use Sobel and Laplacian variant for edge detection.import cv2import numpy as npfrom matplotlib import pyplot as plt# loading image#img0 = cv2.imread('SanFrancisco.jpg',)img0 = cv2.imread('windows.jpg',)# converting to gray scalegray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)# remove noiseimg = cv2.GaussianBlur(gray,(3,3),0)# convolute with proper kernelslaplacian = cv2.Laplacian(img,cv2.CV_64F)sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) # xsobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) # yplt.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()nput:Images used Output: ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download