Code Monkey home page Code Monkey logo

edge-detection's Introduction

Edge-Detection

Aim:

To perform edge detection using Sobel, Laplacian, and Canny edge detectors.

Software Required:

Anaconda - Python 3.7

ALGORITHM:

Step 1:

Import the necessary modules.

Step 2:

Convert image into GRAY using COLOR_BGR2GRAY

Step 3:

Apply Gaussian Blur to the gray image

Step 4:

Perform edge detection on a image.

  • Sobel
  • Laplacian
  • Canny

Step 5:

Display the original images with edge detected images.

Program:

Import the packages

import cv2
from cv2 import COLOR_BGR2GRAY
import matplotlib.pyplot as plt

Load the image, Convert to grayscale and remove noise

input_img = cv2.imread("mikasa.jpg",1)

gray = cv2.cvtColor(input_img,COLOR_BGR2GRAY)

img = cv2.GaussianBlur(gray,(3,3),0)

cv2.imshow("GaussianBlur",img)
cv2.waitKey(0)
cv2.destroyAllWindows()

SOBEL EDGE DETECTOR

sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=9)
sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=13)
sobelxy =cv2.Sobel(img,cv2.CV_64F,1,1,ksize=31)

plt.imshow(img,cmap = 'gray')
plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.show()

plt.imshow(sobelx,cmap = 'gray')
plt.title('sobelx')
plt.xticks([]), plt.yticks([])
plt.show()

plt.imshow(sobely,cmap = 'gray')
plt.title('sobely')
plt.xticks([]), plt.yticks([])
plt.show()

plt.imshow(sobelxy,cmap = 'gray')
plt.title('sobelxy')
plt.xticks([]), plt.yticks([])

plt.show()

LAPLACIAN EDGE DETECTOR

laplacian = cv2.Laplacian(img,cv2.CV_64F)
cv2.imshow("laplacian",laplacian)
cv2.waitKey(0)
cv2.destroyAllWindows()

CANNY EDGE DETECTOR

canny_edges = cv2.Canny(img, 120, 150)
cv2.imshow("Canny",canny_edges)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

SOBEL EDGE DETECTOR

Original Sobel X
image image
Sobel Y Sobel XY
image image

LAPLACIAN EDGE DETECTOR

Original Laplacian
GaussianBlur laplacian

CANNY EDGE DETECTOR

Original Canny Edge
GaussianBlur canny_edges

Result:

Thus the edges are detected using Sobel, Laplacian, and Canny edge detectors.

edge-detection's People

Contributors

shafeeqahameds avatar etjabajasphin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.