You are on page 1of 7

Name of the Subject: Machine Learning Applications

Lab Subject Code: 20CS1109

Week – 3 Lab Record

Name : SRUTHIK THOKALA


Roll No : 20131A05N9
Section : CSE - 4

1
Question:
Write a program for edge detection to extract edge based features from a sample image.

Program Codes & Respective Outputs:


[]: from google.colab import
drive
drive.mount('/content/drive')
O/P: Mounted at /content/drive

[]: import cv2


import numpy as np
from matplotlib import pyplot as plt
import pylab

[]: #Reading an Image from User


a = cv2.imread("img1.jpeg")
plt.imshow(a)
O/P: <matplotlib.image.AxesImage at 0x7fb39c9c5760>

[]: a.shape
O/P: (280,450,3)

[]: # Converting BGR Image to RGB Image


rgb = cv2.cvtColor(a,cv2.COLOR_BGR2RGB)
plt.imshow(rgb)

2
O/P: <matplotlib.image.AxesImage at 0x7fb39c921d30>

3
[]: rgb.shape
O/P: (280,450,3)

[]: # Converting an Image into Gray Scale Image


b = cv2.imread("img1.jpeg", cv2.IMREAD_GRAYSCALE)
plt.imshow(b)
O/P: <matplotlib.image.AxesImage at 0x7fb3ad571ee0>

[]: b.shape
O/P: (280,450)

4
[]: # Converting a BGR Image to HSV Image
c = cv2.cvtColor(a, cv2.COLOR_BGR2HSV)
plt.imshow(c)
O/P: <matplotlib.image.AxesImage at 0x7fb39cba87f0>

[]: c.shape
O/P: (280,450,3)

[]: # Canny Edge Detection


edges = cv2.Canny(a,200,500)
plt.imshow(edges)
O/P: <matplotlib.image.AxesImage at 0x7fb39c7e5af0>

[]: edges.shape
O/P: (1000,1600)
5
[]: d = cv2.imread("img2.jpeg")
# Using Sobel Filter on Images
sx = cv2.Sobel(src=d, ddepth=cv2.CV_64F, dx=0, dy=1,
ksize=3) plt.imshow(sx)
O/P: WARNING:matplotlib.image:Clipping input data to the valid range for imshow with
RGB data ([0..1] for floats or [0..255] for integers).
<matplotlib.image.AxesImage at 0x7fb39ca92790>

[]: sy = cv2.Sobel(src=d, ddepth=cv2.CV_64F, dx=1, dy=0,


ksize=3) plt.imshow(sy)
O/P: WARNING:matplotlib.image:Clipping input data to the valid range for imshow with
RGB data ([0..1] for floats or [0..255] for integers).
<matplotlib.image.AxesImage at 0x7fb39c77cac0>

6
[]: sxy = cv2.Sobel(src=d, ddepth=cv2.CV_64F, dx=0, dy=1,
ksize=3) plt.imshow(sxy)
O/P: WARNING:matplotlib.image:Clipping input data to the valid range for imshow with
RGB data ([0..1] for floats or [0..255] for integers).
<matplotlib.image.AxesImage at 0x7fb39c192700>

You might also like