In this activity, you will implement the convolution operation. Your implementation will detect edges in an image. You are required to implement your convolution function and NOT use existing libraries. Please use the my-cat.csv as your input. Your task is to complete the convolution2D() function in the code below. Hint: You will need to multiply each input pixel (3x3 neighbor grid) of the input 2D array image2D with the input filter kernel3x3 to obtain the output 2D array convolved2D. Note: If you use existing libraries such as scipy.signal.convolve2d, you will not receive any points for your submission
import seaborn as sns import matplotlib.pyplot as plt import numpy as np def convolution2D( image2D, kernel3x3): convolved2D = np.zeros((len( image2D)-2, len(image2D)-2)) # Todo: Write your code here... return convolved2D image2D = np.loadtxt('my-cat.csv', delimiter=',') sns.heatmap( image2D, cmap='gray') plt.title('Original image - Size = ' + str(image2D. shape)) plt.show() edge_detect_filter_3x3 = np.array([[-1, -1, -1), (-1, 8, -1], [-1, -1, -1]]) for i in range(2): convolved_image = convolution 2D(image2D, edge_detect_filter_3x3) sns.heatmap(convolved_image, cmapa' gray) n1+ +*+laliran alist in terations Siya - ctrlronunlvad mana chanel
edge_detect_filter_3x3 = np.array([[-1, -1, -1), (-1, 8, -1], [-1, -1, -1]]) for i in range(2): convolved_image = convolution2D( image2D, edge_detect_filter_3x3) sns.heatmap(convolved_image, cmap='gray) plt.title('Convolution iteration + str(i) +- Size =' + str(convolved_image.shape) plt.show() image2D = convolved_image Expected output: Original images (120 121) Convolution deration - Side (126. 1261 Convolution iteration 15.124.124 -200 0 100 -30 VO -40 -40
In this activity, you will implement the convolution operation. Your implementation will detect edges in an image. You a
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
In this activity, you will implement the convolution operation. Your implementation will detect edges in an image. You a
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!