# detect sharp edges and produce binary output # think of it as high pass filtering operation -> # it allows high frequency content to pass through and blocks # the low frequency content # build a kernel of a high pass filter # we will use sobel filter, whose kernel is # Sx = np.array([[-1,0,1],[-2,0,2],[-1,0,1]]) # Sy = np.array([[-1,-2,-1],[0,0,0],[1,2,1]]) import cv2 import numpy as np import myLibrary image = cv2.imread('image.jpg',cv2.IMREAD_GRAYSCALE) newimage = myLibrary.resize(image,500) # get the shape (height and width) rows,cols = newimage.shape sobel_h = cv2.Sobel(newimage, cv2.CV_64F, 1, 0, ksize=5) sobel_v = cv2.Sobel(newimage, cv2.CV_64F, 0, 1, ksize=5) cv2.imshow('Original Image', newimage) cv2.imshow('Sobel Horizontal', sobel_h) cv2.imshow('Sobel Vertical', sobel_v) # you can also use laplacian filter laplacian = cv2.Laplacian(newimage,cv2.CV_64F) cv2.imshow('Laplacian filter',laplacian) # laplacian give rise to noise in the picture # to overcome that we can use Canny edge detector # a =[]
image = cv2.imread('testimage.jpg') myLibrary.showOriginal(image) cv2.waitKey(0) print() # # time.sleep(2) print("Demonstration Translation (shifting of an object along x and y axis) ") n = input("Enter x and y (seperated by space): ") val = n.split(' ') a = int(val[0]) b = int(val[1]) translatedImage = myLibrary.translate(image,a,b) cv2.imshow("Translated Image",translatedImage) cv2.waitKey(0) print() print("Demonstration of Rotation by an angle") n = int(input("Enter an angle ")) rotatedImage = myLibrary.rotate(image,n) cv2.imshow("Rotated Image",rotatedImage) cv2.waitKey(0) print() print("Demonstration of Resizing") n = input("Enter new width and height (seperated by space): ") val = n.split(' ') width = int(val[0]) height = int(val[1]) resizedImage = myLibrary.resize(image,width,height) cv2.imshow("resizedImage",resizedImage) cv2.waitKey(0)