Question: python : 2d convolution by using numpy I used this dog picture and coded it using only numpy. However, in the im_fillter function part, error

python : 2d convolution by using numpy

I used this dog picture and coded it using only numpy. However, in the im_fillter function part, error : the phrase 6 appears. Please tell me how to modify it.

The code is as follows

python : 2d convolution by using numpy I used this dog picture

and coded it using only numpy. However, in the im_fillter function part,

In [1]: import numpy as np from matplot lib import pyplot as p import cv2 In [2] : def my_imfilter( image, kernel): filtered_image = np.zeros( image. shape) image_padded = np.zeros(( image. shape[0] + 2, image. shape[1] + 2,)) image_padded[1:-1, 1:-1] = image for x in rangel image. shape[1]): for y in range( image. shape[0]): filtered_image[y, x]=(kernel + image_padded[y: yu3, X: X+3] ). sum() print('my_imfilter function in student.py needs to be implemented') return filtered_image In [3] : img = cv2. imread("dog.jpg") image = cv2.cvt Color (img, cv2.COLOR_BGR2RGB) In [4] : kernel = np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) In [5]: filtered_img = my_imfilter( image, kernel) ValueError Traceback (most recent call last) in ----> 1 filtered_img = my_imfilter( image, kernel) in my_imfilter(image, kernel) 4 5 image_padded = np.zeros(( image. shape[O] + 2, image. shape[1] + 2,)) ----> 6 image_padded[1:-1, 1:-1] = image 7 8 for x in rangel image. shape[1]): ValueError: could not broadcast input array from shape (174, 290, 3) into shape (174,290)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!