Posts

Showing posts from March, 2023

Assignment 4: Canny Edge Detection

Image
Image Link:  https://drive.google.com/drive/folders/1USa7N0JCIeGGhZhkKP18-QuziOzh8riX?usp=share_link Canny Edge Detection Algorithm Basic Code: import cv2 import matplotlib.pyplot as plt import numpy as np imPth = r ' c m.jpg' img = plt.imread(imPth) plt.imshow(img, cmap = 'gray' ) E = cv2.Canny(img, 150 , 250 ) plt.subplot( 121 ) plt.imshow(img, cmap = 'gray' ) plt.axis( 'off' ) plt.subplot( 122 ) plt.imshow(E, cmap = 'gray' ) plt.axis( 'off' ) plt.show() Gaussian filter x = 0 y = - 1 sigma = 1 v = ( 1 /( 2 *np.pi*(sigma** 2 )))*np.exp(-(x** 2 + y** 2 )/( 2 *(sigma** 2 ))) v def f_getGaussianFilter ( s , sigma ):     maxX = s// 2     minX = -maxX     minY = minX     maxY = maxX     G = np.zeros((s,s))     for x in range (minX,maxX+ 1 ):         for y in range (minY,maxY+ 1 ):             v = ( 1 /( 2 *np.pi*(sigma** 2 )))*np.exp(-(x** 2 + y** 2 )/( 2 *(sigma** 2 )))             G[x-minX,y-minY] = v     return G G = f_getGaus

Assignment 3: Blurring, Edge, Sharpening

 Image Link:  https://drive.google.com/drive/folders/1I_W9sVXhkm1Ofipu2-GelMfyrp3jViu-?usp=share_link Blurring, Edge, Sharpening Code: import numpy as np import matplotlib.pyplot as plt import cv2 from scipy import signal im = plt.imread( r ' bird.png' )[:,:,: 3 ] imGray = cv2.cvtColor(im,cv2.COLOR_RGB2GRAY) smoothingMask = np.ones(( 15 , 15 ))/ 225 imBlurred = signal.convolve2d(imGray,smoothingMask, boundary = 'symm' , mode = 'same' ) fig,(ax1,ax2) = plt.subplots( 1 , 2 , figsize =( 10 , 15 )) ax1.imshow(imGray, cmap = 'gray' ) ax2.imshow(imBlurred, cmap = 'gray' ) # Edge: xMask = np.array([[- 1 , 0 , 1 ],[- 1 , 0 , 1 ],[- 1 , 0 , 1 ]]) yMask = xMask.T.copy() fx = signal.convolve2d(imGray,xMask, boundary = 'symm' , mode = 'same' ) fy = signal.convolve2d(imGray,yMask, boundary = 'symm' , mode = 'same' ) fx.shape imGray.shape Gm = (fx** 2 + fy** 2 )** 0.5 plt.imshow(Gm, cmap = 'gray' ) th = Gm.max()