Challenge

Project 2

#Importing required libraries
import cv2 as cv
import numpy as np


gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
img_gaussian = cv.GaussianBlur(gray,(3,3),0)              #convert img to gaussian image
kerx = np.array([[1,1,1],[0,0,0],[-1,-1,-1]])
kery = np.array([[-1,0,1],[-1,0,1],[-1,0,1]])             #kernel along x and y axis
imag_prewitt_x = cv.filter2D(img_gaussian, -1, kerx)      #applying prewitt filter to the gaussian image
imag_prewitt_y = cv.filter2D(img_gaussian, -1, kery)  
imag_prewitt=imag_prewitt_x+imag_prewitt_y                 #combining both prewitt filters
cv.imwrite("prewittimage.png",imag_prewitt)               #saving the prewitt image


ddepth = cv.CV_16S                                        #destination depth to avoid overflow of kernel size
ker_size = 3                                              #Declare size of kernel
img_gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)          #Convert to gray
img_gaussian = cv.GaussianBlur(img_gray, (3, 3), 0)       #Apply gaussian filter

laplacianimg = cv.Laplacian(img_gray, ddepth, ksize=ker_size) #obtain laplacian image
cv.imwrite("laplacianimage.png",laplacianimg)
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.