import cv2
import numpy as np
image = cv2.imread('Challenge_2.png')
#Laplacian
laplacian = cv2.Laplacian(image,cv2.CV_8U)#the image is the original image and the CV_8U is the depth of the destination image
#filter is applied in one go for both direction in laplacian
#individual filter is applied in x and y direction an dthen it is combined
#Prewitt
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)#obtain gray image so as to produce Guasssian Blur
image_gaussian = cv2.GaussianBlur(gray,(3,3),0)#obtaining gaussian blur image of the gray image
kernelx = np.array([[1,1,1],[0,0,0],[-1,-1,-1]])#Prewitt Operator [X-axis] to perform convolution in horizontal direction
kernely = np.array([[-1,0,1],[-1,0,1],[-1,0,1]])#Prewitt Operator [Y-axis] to perform convolution in vertical direction
image_prewittx = cv2.filter2D(image_gaussian, -1, kernelx)#cv2.filter2d is used in convolving image with kernel
image_prewitty = cv2.filter2D(image_gaussian, -1, kernely)
laplacian_2 = cv2.Laplacian(image_gaussian,cv2.CV_8U)#applying laplacian filter on guassian image
cv2.imwrite("Original_Image.png", image)
cv2.imwrite("Laplacian_Image.png",laplacian)
cv2.imwrite("Laplacian_2Image.png",laplacian_2)
cv2.imwrite("Prewitt_X.png", image_prewittx)#detecting edges in the horizontal (x)direction
cv2.imwrite("Prewitt_Y.png", image_prewitty)#detecting edges in the vertical(y) direction
cv2.imwrite("Prewitt.png", image_prewittx +image_prewitty)#combining detected edges in x and y direction and producing an image
cv2.waitKey(0)
cv2.destroyAllWindows()